標籤:style color io os 使用 java ar 檔案 sp
為什麼使用 Sea.js ?
Sea.js 簡單、自然的代碼書寫和組織方式
相容性好
技術比較成熟,運用比較普遍。
目錄結構:
examples/ |-- sea-modules 存放 seajs、jquery 等檔案,這也是模組的部署目錄 |-- static 存放各個項目的 js、css 檔案 | |-- hello | |-- lucky | `-- todo `-- app 存放 html 等檔案 |-- hello.html |-- lucky.html `-- todo.html
在頁面中記載模組:
在 hello.html 頁尾,通過 script 引入 sea.js 後,有一段配置代碼:
// seajs 的簡單配置 seajs.config({ base: "../sea-modules/", alias: { "jquery": "jquery/jquery/1.10.1/jquery.js" }}) // 載入入口模組 seajs.use("../static/hello/src/main")
sea.js 在下載完成後,會自動載入入口模組。
代碼模組:
這個小遊戲有兩個模組 spinning.js 和 main.js,遵循統一的寫法:
// 所有模組都通過 define 來定義define(function(require, exports, module) { // 通過 require 引入依賴 var $ = require(‘jquery‘); var Spinning = require(‘./spinning‘); // 通過 exports 對外提供介面 exports.doSomething = ... // 或者通過 module.exports 提供整個介面 module.exports = ... });
上面就是 Sea.js 推薦的 CMD 模組書寫格式。
5 分鐘上手 Sea.js