daxingplay / kmc Goto Github PK
View Code? Open in Web Editor NEWmodule compiler for kissy
License: MIT License
module compiler for kissy
License: MIT License
combo方法目前只支持单文件输出依赖文件。需要考虑支持目录打包输出依赖。
@隐若反馈:moduleCompiler.build的输入文件路径和输出文件路径一样的话,入口模块不会被combo进来
@文龙、@承玉 需求,支持1.3的自动combo功能。
http://docs.kissyui.com/docs/html/tutorials/kissy/seed/loader/common-lib.html#combo
不知能否将java版ModuleCompile中 将html模版文件(.tpl.html)转换为KISSY模块(-tpl.js)的功能添加进来。
KISSY.add(function(S){
S.add('xxx', function(){});
});
这种情况下,会认为模块是xxx
css文件被忽略了貌似
需求来源于承玉
支持把一些kissy本身的模块打包到用户的脚本中,比如dom、event等,需要注意的是分析这些的依赖的时候一个文件内可能有很多的子模块
ubuntu 12.04 LTS
node:0.8.2
module-compiler:0.0.5
/home/qiaofu/node_modules/module-compiler/lib/index.js:471
!self._config.silent && console.info('[err]'.bold.red + ' cannot f
TypeError: Cannot read property 'silent' of undefined
{
mods: [{
output: '/xx/page/xx-out.js', //输出
name: 'page/xx', // 主模块名
path: '/path/to/mod', // 路径
submods: [
{ //所有被打包进来的模块
name: 'utils/mods/a', //被依赖模块名
path: '/path/to/mod', // 被依赖模块的路径 path of mods package
status: 'ok' // 模块状态 如: missing, ok, error
},
{
name: 'utils/mods/a', //被依赖模块名
path: '/path/to/mod', // 被依赖模块的路径 path of mods package
status: 'ok' // 模块状态 如: missing, ok, error
}
]
}]
}
{ 'requires': } 的方式(requires前面有引号之类的)解析会有问题
增加analyze接口,只用来分析依赖,不打包文件,分析完毕后,以json格式输出。
比如
.
|-- menu.js
`-- src
`-- control.js
这么配置:
kmc.config({
packages: [{
name: 'menu',
path: './src',
charset: 'gbk',
ignorePackageNameInUri: true
}]
});
kmc.build('./menu.js')
那么menu.js的模块名就是menu/../menu
,这是因为menu.js文件在包的外面所以不被支持。
理论上这种应该也是支持的:
KISSY.use('menu')
也应该use到这个模块
正常打包不管是否有错都一路成功,不仔细看 log 的话看不到有问题。。。所以,如果有文件错误的话直接抛出来个异常停止掉好了
@maxbbn 提出的。
比如:
ModuleCompiler.config({
packages: [
name: 'abc',
path: 'http://a.tbcdn.cn/s/kissy'
]
});
In file lib/index.js the following use of eval is dangerous
var requiredModules = eval('(' + requires[i]).requires;
A malicious package may place a require clause that would lead to code execution. Either validate all inputs passed to eval using a regex or use a more advanced sanitization library like:
https://github.com/cristianstaicu/eval-sanitizer
只抽取依赖不打包
项目地址:http://gitlab.taobao.ali.com/trip/h5-tt/tree/daily/0.0.21
配置:
options: {
// depFilePath:'build/deps.js',
comboOnly: false,
fixModuleName:true,
comboMap: false,
packages: [
{
name: '<%= pkg.name %>',
path: './src',
charset:'utf-8',
ignorePackageNameInUri:true
}
],
},
main: {
files: [
{
expand: true,
cwd: 'src/',
src: [ '**/*.js', '!Gruntfile.js', '!libs/**/*'],
dest: 'build/'
}
]
}
输出
.
├── config.js
├── mods
│ ├── footer
│ │ └── index.js
│ └── header
│ └── index.js
├── pages
│ ├── detail
│ │ └── index.js
│ ├── list
│ │ ├── index.js
│ │ └── mock.js
│ └── telephone
│ └── index.js
├── test
│ └── abc
│ └── index.js
└── widgets
├── scroll-list
│ └── 1.0
│ └── index.js
└── tabview
└── 1.0
└── index.js
options: {
depFilePath:'build/deps.js',
comboOnly: false,
fixModuleName:true,
comboMap: false,
packages: [
{
name: '<%= pkg.name %>',
path: './src',
charset:'utf-8',
ignorePackageNameInUri:true
}
],
},
main: {
files: [
{
expand: true,
cwd: 'src/',
src: [ '**/*.js', '!Gruntfile.js', '!libs/**/*'],
dest: 'build/'
}
]
}
输出结果
├── test
│ └── abc
│ ├── build
│ │ └── deps.js
│ └── index.js
build/deps.js
options: {
depFilePath:'build/deps.js',
comboOnly: false,
fixModuleName:true,
comboMap: true,
packages: [
{
name: '<%= pkg.name %>',
path: './src',
charset:'utf-8',
ignorePackageNameInUri:true
}
],
},
main: {
files: [
{
expand: true,
cwd: 'src/',
src: [ '**/*.js', '!Gruntfile.js', '!libs/**/*'],
dest: 'build/'
}
]
}
输出结果
├── build
│ └── deps.js
├── config.js
├── deps.js
├── mods
│ ├── footer
│ │ ├── build
│ │ │ └── deps.js
│ │ └── index.js
│ └── header
│ ├── build
│ │ └── deps.js
│ └── index.js
├── pages
│ ├── detail
│ │ ├── build
│ │ │ └── deps.js
│ │ └── index.js
│ └── telephone
│ ├── build
│ │ └── deps.js
│ └── index.js
├── test
│ └── abc
│ ├── build
│ │ └── deps.js
│ └── index.js
└── widgets
├── autocomplete
│ └── 1.0
│ ├── build
│ │ └── deps.js
│ └── index.js
└── tabview
└── 1.0
├── build
│ └── deps.js
└── index.js
options: {
depFilePath:'build/deps.js',
comboOnly: true,
fixModuleName:true,
comboMap: true,
packages: [
{
name: '<%= pkg.name %>',
path: './src',
charset:'utf-8',
ignorePackageNameInUri:true
}
],
},
main: {
files: [
{
expand: true,
cwd: 'src/',
src: [ '**/*.js', '!Gruntfile.js', '!libs/**/*'],
dest: 'build/'
}
]
}
结果:
├── config.js
├── deps.js
├── mods
│ └── header
│ └── mods
│ └── header
│ └── index.js
├── pages
│ ├── detail
│ │ └── pages
│ │ └── detail
│ │ └── index.js
│ ├── global
│ │ └── pages
│ │ └── global
│ │ └── index.js
│ ├── list
│ │ └── pages
│ │ ├── global
│ │ │ └── index.js
│ │ └── list
│ │ ├── index.js
│ │ └── mock.js
│ ├── news
│ │ └── pages
│ │ └── news
│ │ └── index.js
│ ├── news-list
│ │ └── pages
│ │ └── news-list
│ │ └── index.js
│ ├── query
│ │ ├── pages
│ │ │ ├── global
│ │ │ │ └── index.js
│ │ │ └── query
│ │ │ └── index.js
│ │ └── widgets
│ │ ├── checkbox
│ │ │ └── 1.0
│ │ │ └── index.js
│ │ └── radio
│ │ └── 1.0
│ │ └── index.js
│ ├── station
│ │ ├── pages
│ │ │ ├── global
│ │ │ │ └── index.js
│ │ │ └── station
│ │ │ └── index.js
│ │ └── widgets
│ │ ├── autocomplete
│ │ │ └── 1.0
│ │ │ └── index.js
│ │ ├── scroll-list
│ │ │ └── 1.0
│ │ │ └── index.js
│ │ └── tabview
│ │ └── 1.0
│ │ └── index.js
│ └── telephone
│ └── pages
│ └── telephone
│ └── index.js
├── test
│ └── abc
│ └── test
│ └── abc
│ └── index.js
└── widgets
├── autocomplete
│ └── 1.0
│ └── widgets
│ └── autocomplete
│ └── 1.0
│ └── index.js
├── checkbox
│ └── 1.0
│ └── widgets
│ └── checkbox
│ └── 1.0
│ └── index.js
├── loading
│ └── 1.0
│ └── widgets
│ └── loading
│ └── 1.0
│ └── index.js
├── radio
│ └── 1.0
│ └── widgets
│ └── radio
│ └── 1.0
│ └── index.js
├── scroll-list
│ └── 1.0
│ └── widgets
│ └── scroll-list
│ └── 1.0
│ └── index.js
└── tabview
└── 1.0
└── widgets
└── tabview
└── 1.0
└── index.js
支持KISSY的alias配置:
http://docs.kissyui.com/1.4/docs/html/tutorials/kissy/loader/alias.html#loader-alias-tutorial
配置了alias之后,就会用别名模块替换原模块打包。
kissy自带的模块,比如dom、event打包进来的时候不能添加包名。
input支持目录
@林谦 需求:build的时候指定了目录,可以排除该目录下的一些特定文件,比如-min.js,-combine.js
关于非相对路径模块合并依赖 比如我require['./test','global/test']
./test就合并进来,global/test就合并不进来
是需要怎么设置么
例子:
KISSY.add(function(S) {
var triggers = S.all('.selector1').add('.selector2');
....
});
由于代码中调用了这个add方法,会导致整个模块无法被打包,但不会终端整个打包流程(感觉像是跳过了该模块)。
@拔赤 的需求,遍历文件夹的时候需要遍历所有的子目录,这样,每个模块文件都可以单独被use,讨论了一下,打包的时候单独增加一个参数解决这个问题。
see daxingplay/grunt-kmc#9 for more details
exclude貌似没用。
感觉这是一种陋习~
combo一次就加一个回车,防止下一个文件和上一个文件的末尾粘连,不好看。
require: ['pkg/mod/']
比如:
ModuleCompiler.build('pkgName/index')
方便替换模块名
即支持下面的这种配置包的方式:
KISSY.config({
packages:{
x:{
// x 包的基准路径
base:'http://x.com/biz/',
// x 包的时间戳
tag:'x',
// 开启 x 包 debug 模式
debug:true
},
y:{
// y 包的基准路径
base:'http://x.com/biz/',
// y 包不开启自动 combo
combine:false
// 不配置 tag,则取 kissy 内置模块的时间戳
}
}
}
build这个api,如果不配置outputFilePath的话,将文件内容带出来。
或者统一一下,都带出来
之前有做处理,但是这次发现如果两个模块中一个是入口文件就会有问题,应该是之前的处理位置不对
如果文件带有BOM头,那么打包的时候会成问号:?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.