SlideShare a Scribd company logo
1 of 20
前端模块化开发2015/03/31 @fuqiang3
http://en.wikipedia.org/wiki/CommonJS
http://wiki.ecmascript.org/doku.php?id=harmony:modules
javascript 模块化
优点
• 标准,易用,工程化
• 分布式,解耦依赖,复用性高
缺点
• 前端请求数较多
• 需要构建工程
• 模块命名数较多,粒度控制复杂
方案
• commonjs AMD/CMD
• ES6 modules loader
• $import/$include
Lithe.js
Flexible front-end javascript loader
什么是 lithe.js
A browser-side script loader,compatible with the de facto
standards(NodeJS/CommonJS). It's very simple and small,only 2.7kb gzipped.
怎么用?
• define
• require
• use
• config
define
//path/to/file.js
define('path/to/file',function(require,exports,module){
var file = 'path/to/file.js';
exports.filename = 'file.js';
exports.filedir = 'path/to/';
/**
* module.exports = {
* filename:'file.js',
* filedir:'path/to'
* };
*/
});
require
//path/to/app.js
define('path/to/app',function(require,exports,module){
var file = require('path/to/file');
console.log(file.filename); //file.js
console.log(file.filedir); //path/to
module.exports = 'i am app.js';
});
use
//anywhere
lithe.use('path/to/app',function(app){
console.log(app); // i am app.js
});
//or
lithe.use('a.js','b.js',function(a,b){
//a and b has required;
});
config
define('config',function(require,exports,module){
module.exports = {
//it will replace the real BASEPATH
basepath:'http://localhost/debug/path',
//logogram
alias:{
'app':'path/to/app',
'file':'path/to/file',
//Relative directory proxy
'UI':'../'
}
};
});
define('someOtherJs',function(){
var app = require('app'),
file = require('file');
});
如何构建?
If you use GruntJs to build your project , you can use
grunt-lithe or use lithe’s Nodejs API.
怎么部署到页面
<script src="lithe.js"
data-config="config.js"
data-path="http://domain.com/"
data-debug="true"
data-main="app.js">
</script>
文档
https://github.com/litheModule/lithe
实战
https://github.com/litheModule/litheExample
http://news.sina.com.cn/c/z/2015qglh/
Q&A

More Related Content

Viewers also liked

Proses penyusunan rencana kerja sekolah
Proses penyusunan rencana kerja sekolahProses penyusunan rencana kerja sekolah
Proses penyusunan rencana kerja sekolahSUKAWANGI03
 
Серавин. политуправление. параметры выборов глав регионов сз
Серавин. политуправление. параметры выборов глав регионов сзСеравин. политуправление. параметры выборов глав регионов сз
Серавин. политуправление. параметры выборов глав регионов сзValentine Bianki
 
Deutsch lernen und lehren mit digitalen medien
Deutsch lernen und lehren mit digitalen medienDeutsch lernen und lehren mit digitalen medien
Deutsch lernen und lehren mit digitalen medienbfnd
 
primeros auxilios
primeros auxiliosprimeros auxilios
primeros auxiliosolmedo07
 
eCommerce day 2017 - Business part - Soft Uni
eCommerce day 2017 - Business part - Soft UnieCommerce day 2017 - Business part - Soft Uni
eCommerce day 2017 - Business part - Soft UniTendrik
 
A teoria sintética do Darwin
A teoria sintética do DarwinA teoria sintética do Darwin
A teoria sintética do DarwinPedro Kangombe
 
Questoes da bahiana com gabarito
Questoes da bahiana com gabarito Questoes da bahiana com gabarito
Questoes da bahiana com gabarito brandaobio
 
Н.К. Куричев - Пространственная трансформация Московской агломерации и межрег...
Н.К. Куричев - Пространственная трансформация Московской агломерации и межрег...Н.К. Куричев - Пространственная трансформация Московской агломерации и межрег...
Н.К. Куричев - Пространственная трансформация Московской агломерации и межрег...Moscow School of Economics (MSE MSU)
 

Viewers also liked (12)

Las plantas
Las plantasLas plantas
Las plantas
 
Presentation Xcape
Presentation XcapePresentation Xcape
Presentation Xcape
 
Proses penyusunan rencana kerja sekolah
Proses penyusunan rencana kerja sekolahProses penyusunan rencana kerja sekolah
Proses penyusunan rencana kerja sekolah
 
Серавин. политуправление. параметры выборов глав регионов сз
Серавин. политуправление. параметры выборов глав регионов сзСеравин. политуправление. параметры выборов глав регионов сз
Серавин. политуправление. параметры выборов глав регионов сз
 
Deutsch lernen und lehren mit digitalen medien
Deutsch lernen und lehren mit digitalen medienDeutsch lernen und lehren mit digitalen medien
Deutsch lernen und lehren mit digitalen medien
 
primeros auxilios
primeros auxiliosprimeros auxilios
primeros auxilios
 
eCommerce day 2017 - Business part - Soft Uni
eCommerce day 2017 - Business part - Soft UnieCommerce day 2017 - Business part - Soft Uni
eCommerce day 2017 - Business part - Soft Uni
 
A teoria sintética do Darwin
A teoria sintética do DarwinA teoria sintética do Darwin
A teoria sintética do Darwin
 
União africana
União africanaUnião africana
União africana
 
Questoes da bahiana com gabarito
Questoes da bahiana com gabarito Questoes da bahiana com gabarito
Questoes da bahiana com gabarito
 
Н.К. Куричев - Пространственная трансформация Московской агломерации и межрег...
Н.К. Куричев - Пространственная трансформация Московской агломерации и межрег...Н.К. Куричев - Пространственная трансформация Московской агломерации и межрег...
Н.К. Куричев - Пространственная трансформация Московской агломерации и межрег...
 
Third session
Third sessionThird session
Third session
 

More from xiaojueqq12345

Fds-给前端用的服务器
Fds-给前端用的服务器Fds-给前端用的服务器
Fds-给前端用的服务器xiaojueqq12345
 
Web program-peformance-optimization
Web program-peformance-optimizationWeb program-peformance-optimization
Web program-peformance-optimizationxiaojueqq12345
 
淘宝帮派活动项目总结
淘宝帮派活动项目总结淘宝帮派活动项目总结
淘宝帮派活动项目总结xiaojueqq12345
 

More from xiaojueqq12345 (6)

Fds-给前端用的服务器
Fds-给前端用的服务器Fds-给前端用的服务器
Fds-给前端用的服务器
 
Voluminous_Weibo
Voluminous_WeiboVoluminous_Weibo
Voluminous_Weibo
 
nodejs开发web站点
nodejs开发web站点nodejs开发web站点
nodejs开发web站点
 
Web program-peformance-optimization
Web program-peformance-optimizationWeb program-peformance-optimization
Web program-peformance-optimization
 
Mxhr
MxhrMxhr
Mxhr
 
淘宝帮派活动项目总结
淘宝帮派活动项目总结淘宝帮派活动项目总结
淘宝帮派活动项目总结
 

前端模块化开发