Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
SeaJS TUI实践
Search
luolonghao
May 22, 2013
Technology
99
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
SeaJS TUI实践
luolonghao
May 22, 2013
More Decks by luolonghao
See All by luolonghao
About HRT and TPM
luolonghao
0
80
KindEditor 设计思路 V2
luolonghao
1
180
Other Decks in Technology
See All in Technology
DEFCON_CHV_CTF_Write-up.pdf
bata_24
0
150
積み重なった技術負債への挑戦 〜初手としての全社ゴト化〜
techtekt
PRO
0
1.3k
データ_AIの事業の勝敗をわけるもの
nek0128
0
390
安心して変更できるWebフロントエンドの作り方
pirosikick
5
2.6k
映像変換サーバーなしで端末内でHLSを生成してライブ配信
hikarusato
0
120
Claude in Chrome 入門 / Introduction to Claude in Chrome
cielo1985
0
830
AI時代、データエンジニアが一番おもろい
genshun9
0
620
Claude Codeを「使うほど育つ」AI秘書にするノウハウ
minorun365
PRO
30
26k
事業課題から技術的負債に向き合う
sansantech
PRO
2
1.9k
GoのInterface内部構造から学ぶ!最高パフォーマンスを出すコード設計
yappli_developers
0
110
AIを活用するために決めた "やらないこと" - 価値に注目する / Not betting on AI
soudai
PRO
2
540
「守り」で活用するオンデバイスLLM 〜写ってはいけないを総力戦で防ぐ〜 / iOSDC Japan 2026
nakamuuu
0
160
Featured
See All Featured
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.8k
What's in a price? How to price your products and services
michaelherold
247
13k
Between Models and Reality
mayunak
4
460
So, you think you're a good person
axbom
PRO
2
2.2k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
[SF Ruby Conf 2025] Rails X
palkan
3
1.4k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
510
エンジニアに許された特別な時間の終わり
watany
109
250k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.3k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
500
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
12k
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