Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
SeaJS TUI实践
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
luolonghao
May 22, 2013
Technology
95
0
Share
SeaJS TUI实践
luolonghao
May 22, 2013
More Decks by luolonghao
See All by luolonghao
About HRT and TPM
luolonghao
0
74
KindEditor 设计思路 V2
luolonghao
1
180
Other Decks in Technology
See All in Technology
AIでAIをテストする - 音声AIエージェントの品質保証戦略
morix1500
1
150
260422_Sansan_Tech_Talk__関西_vol.3_データ活用のリアル__矢田__.pdf
sansantech
PRO
0
130
AI活用時代の事業判断高度化を導くエンジニアリング基盤 / 20260424 Atsushi Funahashi
shift_evolve
PRO
2
100
弁護士ドットコム株式会社 エンジニア職向け 会社紹介資料
bengo4com
1
190
コミュニティ・勉強会を作るのは目的じゃない
ohmori_yusuke
0
270
巨大プラットフォームを進化させる「第3のROI」
recruitengineers
PRO
2
1.4k
Choose your own adventure in agentic design patterns
glaforge
0
160
プラットフォームエンジニアリングの実践 - AWS コンテナサービスで構築する社内プラットフォーム / AWS Containers Platform Meetup #1
literalice
1
220
バイブコーディングで3倍早く⚪⚪を作ってみた
samakada
0
180
需要創出(Chatwork)×供給(BPaaS) フライホイールとMoat 実行能力の最適配置とAI戦略
kubell_hr
0
1k
音声言語モデル手法に関する発表の紹介
kzinmr
0
140
「AIに部下10人」を3ヶ月運用してわかった、生成AI駆動開発のリアル
yoheinabe777
0
110
Featured
See All Featured
Into the Great Unknown - MozCon
thekraken
41
2.4k
Docker and Python
trallard
47
3.8k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
118
110k
Designing for Performance
lara
611
70k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
65
55k
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
99
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
140
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
How to Think Like a Performance Engineer
csswizardry
28
2.6k
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
160
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
160
Transcript
SeaJS + TUI实践 2012.10.08
SeaJS、CMD SeaJS:模块加载器 CMD:SeaJS的模块定义规范
入门代码(HTML) <!doctype html> <html> <head> <title>Hello</title> </head> <body> <script src=“http://js.tudouui.com/js/v3/seajs/sea.js"></script>
<script> seajs.config({ alias: { 'jquery‘ : ‘jquery/1.7.2/jquery.js‘, ‘hello’ : ’hello/dist/hello.js’ }, base : ‘http://js.tudouui.com/js/v3/’ }); seajs.use('/page/demo/dist/main.js'); </script> </body> </html>
入门代码(main.js) define(function(require, exports, module) { var Hello = require(‘hello'); new
Hello(); });
入门代码(hello.js) define(function(require, exports, module) { var $ = require('jquery'); function
Hello(){ this.render(); }; Hello.prototype.render = function(){ $('<h1>Hello SeaJS !</h1>').appendTo('body'); }; return Hello; });
目录结构 static/v3/ jquery/ 1.8.1/ json/ 1.0.2/ tui/ dist/ src/ tuilib/
dist/ src/ hello/ dist/ src/ page/ demo/ dist/ src/
改造老代码 • 用define(function(require) {…});包起来 • @import ./xxx.js改成require(‘./xxx’); • 用window暴露全局变量,或用exports返回 •
TUI.module.use(‘/fn/tuidefer’, fn)改成require.async(‘tuidefer’, fn) • TUI.convertTpl(‘./xxx.tpl‘, data)改成TUI.convertTpl(require(‘./xxx.tpl’), data)
这样做有什么好处? • 可在浏览器端加载依赖,这样页面可以直 接调用源代码,无需打包,对单元测试友 好 • 控制入口,可重写任何URL(比如,加时间 戳,用debug插件调试) • 与Node模块非常相近,很容易迁移
单元测试(V2) // stat.js,通过打包工具合并后才能调用 /** * @import fn/MRG32k3a.js * @import fn/global/common_stat.js
* @import fn/global/pv_stat.js * @import fn/global/expose_stat.js */ var ComboPvStat = { // some code }; ComboPvStat.send();
单元测试(V3) // stat.js,可以直接调用,无需打包 define(function(require, exports, module) { require('./MRG32k3a'); require('./common_stat'); require('./pv_stat');
require('./expose_stat'); var ComboPvStat = { // some code }; ComboPvStat.send(); });
调试(V2) 依赖本地代理(makeasy)
调试(V3) 本地运行HTTP服务,URL后加seajs-debug参数 // debug.js rules.push([ 'http://js.tudouui.com/js/v3/page/demo/dist', 'http://localhost/js/v3/page/demo/src' ]);
打包、压缩(V2)
打包、压缩(V3) // 安装SPM $ git clone https://github.com/seajs/spm.git $ cd spm
$ npm install –g // 打包、压缩 $ cd v3/hello $ spm build
参考文档 V3代码: trunk/static/js/v3 SeaJS:http://seajs.org/docs/#api CMD:https://github.com/seajs/seajs/issues/242 SPM:https://github.com/seajs/spm/wiki