Suche senden
Hochladen
SeaJS 那些事儿
•
6 gefällt mir
•
1,608 views
L
lifesinger
Folgen
Technologie
Bildung
Melden
Teilen
Melden
Teilen
1 von 46
Jetzt herunterladen
Downloaden Sie, um offline zu lesen
Empfohlen
YUI is Sexy (for JSDC.tw)
YUI is Sexy (for JSDC.tw)
Joseph Chiang
YUI 教學 - 前端工程開發實務訓練
YUI 教學 - 前端工程開發實務訓練
Joseph Chiang
Kissy模块化实践
Kissy模块化实践
yiming he
YUI is Sexy - 使用 YUI 作為開發基礎
YUI is Sexy - 使用 YUI 作為開發基礎
Joseph Chiang
SeaJS - 前端模块化开发探索与网站性能优化实践
SeaJS - 前端模块化开发探索与网站性能优化实践
lifesinger
前端工程開發實務訓練
前端工程開發實務訓練
Joseph Chiang
Top100summit前端的云时代支付宝前端平台架构 王保平
Top100summit前端的云时代支付宝前端平台架构 王保平
drewz lin
开放式类库的构建
开放式类库的构建
lifesinger
Empfohlen
YUI is Sexy (for JSDC.tw)
YUI is Sexy (for JSDC.tw)
Joseph Chiang
YUI 教學 - 前端工程開發實務訓練
YUI 教學 - 前端工程開發實務訓練
Joseph Chiang
Kissy模块化实践
Kissy模块化实践
yiming he
YUI is Sexy - 使用 YUI 作為開發基礎
YUI is Sexy - 使用 YUI 作為開發基礎
Joseph Chiang
SeaJS - 前端模块化开发探索与网站性能优化实践
SeaJS - 前端模块化开发探索与网站性能优化实践
lifesinger
前端工程開發實務訓練
前端工程開發實務訓練
Joseph Chiang
Top100summit前端的云时代支付宝前端平台架构 王保平
Top100summit前端的云时代支付宝前端平台架构 王保平
drewz lin
开放式类库的构建
开放式类库的构建
lifesinger
Node js实践
Node js实践
myzykj
Kissy design
Kissy design
yiming he
J engine -构建高性能、可监控的前端应用框架
J engine -构建高性能、可监控的前端应用框架
wtxidian
July.2011.w3ctech
July.2011.w3ctech
Kai Cui
J engine -构建高性能、可监控的前端应用框架
J engine -构建高性能、可监控的前端应用框架
fangdeng
基于Seajs的项目构建
基于Seajs的项目构建
Zhang Xiaoxue
Intro-to-SeaJS
Intro-to-SeaJS
lifesinger
建立前端开发团队 (Front-end Development Environment)
建立前端开发团队 (Front-end Development Environment)
Joseph Chiang
NodeJS基礎教學&簡介
NodeJS基礎教學&簡介
GO LL
Javascript autoload
Javascript autoload
jay li
使用kslite支持第三方内容开发
使用kslite支持第三方内容开发
leneli
Spring 2.x 中文
Spring 2.x 中文
Guo Albert
a glance of Javascript module
a glance of Javascript module
zipeng zhang
Template mb-kao
Template mb-kao
xwcoder
OPOA in Action -- 使用MagixJS简化WebAPP开发
OPOA in Action -- 使用MagixJS简化WebAPP开发
leneli
Programming in Objective-C
Programming in Objective-C
Ryan Chung
Introduction to MVC of CodeIgniter 2.1.x
Introduction to MVC of CodeIgniter 2.1.x
Bo-Yi Wu
Node.js在淘宝的应用实践
Node.js在淘宝的应用实践
taobao.com
模块加载策略 - 2012 SDCC, 北京
模块加载策略 - 2012 SDCC, 北京
Joseph Chiang
Asp.net mvc網站的從無到有
Asp.net mvc網站的從無到有
Wade Huang
让开发也懂前端
让开发也懂前端
lifesinger
SeaJS - 跨环境模块化开发实践
SeaJS - 跨环境模块化开发实践
lifesinger
Weitere ähnliche Inhalte
Ähnlich wie SeaJS 那些事儿
Node js实践
Node js实践
myzykj
Kissy design
Kissy design
yiming he
J engine -构建高性能、可监控的前端应用框架
J engine -构建高性能、可监控的前端应用框架
wtxidian
July.2011.w3ctech
July.2011.w3ctech
Kai Cui
J engine -构建高性能、可监控的前端应用框架
J engine -构建高性能、可监控的前端应用框架
fangdeng
基于Seajs的项目构建
基于Seajs的项目构建
Zhang Xiaoxue
Intro-to-SeaJS
Intro-to-SeaJS
lifesinger
建立前端开发团队 (Front-end Development Environment)
建立前端开发团队 (Front-end Development Environment)
Joseph Chiang
NodeJS基礎教學&簡介
NodeJS基礎教學&簡介
GO LL
Javascript autoload
Javascript autoload
jay li
使用kslite支持第三方内容开发
使用kslite支持第三方内容开发
leneli
Spring 2.x 中文
Spring 2.x 中文
Guo Albert
a glance of Javascript module
a glance of Javascript module
zipeng zhang
Template mb-kao
Template mb-kao
xwcoder
OPOA in Action -- 使用MagixJS简化WebAPP开发
OPOA in Action -- 使用MagixJS简化WebAPP开发
leneli
Programming in Objective-C
Programming in Objective-C
Ryan Chung
Introduction to MVC of CodeIgniter 2.1.x
Introduction to MVC of CodeIgniter 2.1.x
Bo-Yi Wu
Node.js在淘宝的应用实践
Node.js在淘宝的应用实践
taobao.com
模块加载策略 - 2012 SDCC, 北京
模块加载策略 - 2012 SDCC, 北京
Joseph Chiang
Asp.net mvc網站的從無到有
Asp.net mvc網站的從無到有
Wade Huang
Ähnlich wie SeaJS 那些事儿
(20)
Node js实践
Node js实践
Kissy design
Kissy design
J engine -构建高性能、可监控的前端应用框架
J engine -构建高性能、可监控的前端应用框架
July.2011.w3ctech
July.2011.w3ctech
J engine -构建高性能、可监控的前端应用框架
J engine -构建高性能、可监控的前端应用框架
基于Seajs的项目构建
基于Seajs的项目构建
Intro-to-SeaJS
Intro-to-SeaJS
建立前端开发团队 (Front-end Development Environment)
建立前端开发团队 (Front-end Development Environment)
NodeJS基礎教學&簡介
NodeJS基礎教學&簡介
Javascript autoload
Javascript autoload
使用kslite支持第三方内容开发
使用kslite支持第三方内容开发
Spring 2.x 中文
Spring 2.x 中文
a glance of Javascript module
a glance of Javascript module
Template mb-kao
Template mb-kao
OPOA in Action -- 使用MagixJS简化WebAPP开发
OPOA in Action -- 使用MagixJS简化WebAPP开发
Programming in Objective-C
Programming in Objective-C
Introduction to MVC of CodeIgniter 2.1.x
Introduction to MVC of CodeIgniter 2.1.x
Node.js在淘宝的应用实践
Node.js在淘宝的应用实践
模块加载策略 - 2012 SDCC, 北京
模块加载策略 - 2012 SDCC, 北京
Asp.net mvc網站的從無到有
Asp.net mvc網站的從無到有
Mehr von lifesinger
让开发也懂前端
让开发也懂前端
lifesinger
SeaJS - 跨环境模块化开发实践
SeaJS - 跨环境模块化开发实践
lifesinger
Progressive Enhancement
Progressive Enhancement
lifesinger
KISSY Mechanism
KISSY Mechanism
lifesinger
The Beauty Of Refactoring
The Beauty Of Refactoring
lifesinger
Closure Compiler vs YUICompressor
Closure Compiler vs YUICompressor
lifesinger
Mehr von lifesinger
(6)
让开发也懂前端
让开发也懂前端
SeaJS - 跨环境模块化开发实践
SeaJS - 跨环境模块化开发实践
Progressive Enhancement
Progressive Enhancement
KISSY Mechanism
KISSY Mechanism
The Beauty Of Refactoring
The Beauty Of Refactoring
Closure Compiler vs YUICompressor
Closure Compiler vs YUICompressor
SeaJS 那些事儿
1.
SeaJS 那些事儿
seajs.org 2012 1
2.
About Me •王保平 /
lifesinger / 玉伯 / 射雕 •支付宝 -‐ 前端开发部 -‐ 基础技术组 •KISSY、SeaJS、Arale、布道、翻译 2
3.
Topics •SeaJS 是什么 •核心设计与实现 •谈谈开源 •未来规划
3
4.
I. SeaJS 是什么
4
5.
SeaJS
is A Module Loader for the Web SeaJS 是 适用于 Web 端的模块加载器 5
6.
以 seajs.org 为例
6
7.
SeaJS 的应用场景 •SeaJS 是更自然的代码组织方式 •只要项目的
JS 文件超过 3 个,就适合用 •文件越多,则越适合 •误解:SeaJS 不适合小项目 以 Jscex 为例 7
8.
II. 核心设计与实现
8
9.
模块系统
9
10.
什么是系统 •
系统由个体组成 • 个体之间有关连,按照规则协同完成任务 https://github.com/seajs/seajs/issues/240 10
11.
模块系统的基本问题 • 系统成员:模块是什么? • 系统通讯:模块之间如何交互?
11
12.
模块定义规范 CommonJS
AMD Modules / 1.1 CMD Node Modules Intel ... CommonJS Modules / 2.0 12
13.
CMD •CMD -‐ Common
Module Definition •尽量与 CommonJS Modules/1.1 以及 Node Modules 的规范保持⼀一致 •同时考虑 Web 特性 13
14.
CMD define(function(require, exports, module)
{ var $ = require(‘jquery’) var math = require(‘./math’) exports.doSomething = ... }) https://github.com/seajs/seajs/issues/242 14
15.
模块加载器
15
16.
加载器的基本功能 • 模块定义规范的实现,这是模块系统的基础。 • 模块系统的启动与运行。
https://github.com/seajs/seajs/issues/260 16
17.
Node 的实现
var math = require(‘./math’) Step 1: resolveFilename Step 2: load Step 3: compile Step 4: return module.exports https://github.com/joyent/node/blob/master/lib/module.js 17
18.
从 Server 到
Web • node_modules 查找不适合 Web 端 • 文件的同步读取不适合 Web 端 • Web 端的依赖需要提前获取 18
19.
SeaJS 的实现 /* a.js
*/ define(function(require, exports, module) { var b = require(‘./b’) /* main.js */ var c = require(‘./c’) seajs.use(‘./a’) // ... }) Step 1: 解析 ‘./a’ Step 2.1: 下载 a Step 2.2: 执行 define,保存 a 的 factory Step 2.3: 得到依赖 b 和 c Step 2.4: 加载 b 和 c Step 3: 执行 a 的 factory,得到 a 的 module.exports 19
20.
Step 1: 路径解析
seajs.use({ require(‘jquery’) alias: { parseAlias ‘jquery’: ‘jquery/1.7.2/jquery.js’ }, require(‘jquery/1.7.2/jquery.js’) id2uri map: [ [ http://example.com/libs/jquery/1.7.2/jquery.js /^.*jquery.js$/, ‘http://localhost/path/to/jquery.js’ parseMap ] ] http://localhost/path/to/jquery.js }) 20
21.
Step 2: 模块加载
script 异步获取 获取文件 plugin-‐text XHR 同步或异步获取 plugin-‐less plugin-‐coffee plugin-‐json ... 21
22.
如何得到依赖?
factory.toString() + 正则匹配 https://github.com/seajs/seajs/blob/master/src/util-‐deps.js require(‘./xxx’) Rule 1: factory 第⼀一个参数的命名必须是 require Rule 2: require 函数只能接收字符串值 Rule 3: 不要覆盖 require http://seajs.org/docs/zh-‐cn/rules.html 22
23.
依赖的回调树
e f g h d b c a 23
24.
循环依赖
e h d b c g f a 24
25.
加载时的循环等待
isCircularWaiting(module, uri) https://github.com/seajs/seajs/blob/master/src/module.js 25
26.
编译时的循环等待
if (module.status === STATUS.COMPILING) { return module.exports } https://github.com/seajs/seajs/blob/master/src/module.js 26
27.
Step 3: 代码编译
module.require = require /* a.js */ module.exports = {} define(function(require, exports, module) { var b = require(‘./b’) module.factory.call( var c = require(‘./c’) window, // ... module.require, }) module.exports, module ) 27
28.
编译前后
factory 通过 factory.toString 拿到源码 plugin-‐codelint factory.call 在反馈给用户之前可以做修改 seajs.modify module.exports 1. 紧急修复 bug 2. 测试 mock 3. ... 28
29.
实现小结 • 路径解析:id --
uri • 依赖加载:toString / onload / ... • 代码编译:factory.call 29
30.
SeaJS 的可靠性
30
31.
SeaJS 的基本假设
A -‐-‐-‐ 表示 a.js 执行时的时间 a -‐-‐-‐ 表示 a.js 的 onload / onerror 时的时间 开发时,SeaJS 要求:A 与 a 紧相邻 上线后,SeaJS 要求:A < a http://seajs.org/test/research/onload-‐order/test.html https://github.com/seajs/seajs/issues/130 31
32.
疯狂的测试用例 http://seajs.org/test/runner.html
PC、Mobile 理论上是个浏览器就应该可以跑 32
33.
已有哪些公司在用
33
34.
More •seajs.log / seajs.cache
/ seajs.find / seajs.modify •plugin-‐text / plugin-‐json / plugin-‐combo / plugin-‐coffee / plugin-‐less / plugin-‐ livereload / plugin-‐codelint / ... •seajs.pluginSDK 34
35.
III. 谈谈开源
35
36.
开源的目的 • 把好的东西分享出来 • 让好的东西变得更好 •
其他⼀一切皆是浮云 36
37.
开源中最重要的 • ⼀一个优秀、靠谱的想法 • 疯狂而持久的坚持 开源项目起步时,梦想都很丰满,但 现实都很骨感。很多人等不到后天的 太阳,经常离开于明天的晚上。
37
38.
IV. 未来规划
38
39.
SeaJS v1.2.0 https://github.com/seajs/seajs/issues/190
SeaJS v1.2 will release SOON ! 39
40.
SeaJS v1.3.0 https://github.com/seajs/seajs/issues/225
40
41.
SPM 1.0 will release
at Jul 30 No 跳票 again! 41
42.
不仅仅是模块加载器 •JavaScript 模块生态圈之梦 •Arale 的尝试 •SPM
仓库 42
43.
Questions?
43
44.
与 RequireJS 对比 •API
设计上比 RequireJS 更优秀 •实现上比 RequireJS 更优秀 •理念上比 RequireJS 更优秀 •更懂中国人 44
45.
向 CommonJS /
NodeJS / UnCommonJS / FlyScript / RequireJS / ... 致敬!!! 45
46.
}); seajs.org
46
Jetzt herunterladen