$30 off During Our Annual Pro Sale. View Details »

SeaJS TUI实践

SeaJS TUI实践

luolonghao

May 22, 2013
Tweet

More Decks by luolonghao

Other Decks in Technology

Transcript

  1. 入门代码(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>
  2. 入门代码(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; });
  3. 目录结构 static/v3/ jquery/ 1.8.1/ json/ 1.0.2/ tui/ dist/ src/ tuilib/

    dist/ src/ hello/ dist/ src/ page/ demo/ dist/ src/
  4. 改造老代码 • 用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)
  5. 单元测试(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();
  6. 打包、压缩(V3) // 安装SPM $ git clone https://github.com/seajs/spm.git $ cd spm

    $ npm install –g // 打包、压缩 $ cd v3/hello $ spm build