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
luolonghao
May 22, 2013
Technology
0
95
SeaJS TUI实践
luolonghao
May 22, 2013
Tweet
Share
More Decks by luolonghao
See All by luolonghao
About HRT and TPM
luolonghao
0
72
KindEditor 设计思路 V2
luolonghao
1
180
Other Decks in Technology
See All in Technology
NewSQL_ ストレージ分離と分散合意を用いたスケーラブルアーキテクチャ
hacomono
PRO
4
420
Windows ファイル共有(SMB)を再確認する
murachiakira
PRO
0
210
ソフトバンク流!プラットフォームエンジニアリング実現へのアプローチ
sbtechnight
1
230
Everything Claude Code を眺める
oikon48
13
8.7k
社内レビューは機能しているのか
matsuba
0
170
Claude Code 2026年 最新アップデート
oikon48
14
11k
脳内メモリ、思ったより揮発性だった
koutorino
0
390
「お金で解決」が全てではない!大規模WebアプリのCI高速化 #phperkaigi
stefafafan
4
1.9k
バクラク最古参プロダクトで重ねた技術投資を振り返る
ypresto
0
190
【Λ(らむだ)】最近のアプデ情報 / RPALT20260318
lambda
0
120
エンジニアリングマネージャーの仕事
yuheinakasaka
0
120
2026年もソフトウェアサプライチェーンのリスクに立ち向かうために / Product Security Square #3
flatt_security
1
700
Featured
See All Featured
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
200
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
640
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
150
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.7k
Ethics towards AI in product and experience design
skipperchong
2
230
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
860
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
84
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3.4k
Odyssey Design
rkendrick25
PRO
2
550
エンジニアに許された特別な時間の終わり
watany
106
240k
YesSQL, Process and Tooling at Scale
rocio
174
15k
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