Comparing version 0.1.15 to 0.1.17
{ | ||
"name": "grunt-kmc", | ||
"description": "Grunt plugin for KISSY Module Compiler", | ||
"version": "0.1.15", | ||
"version": "0.1.17", | ||
"homepage": "https://github.com/daxingplay/grunt-kmc", | ||
@@ -6,0 +6,0 @@ "author": { |
162
README.md
@@ -23,3 +23,3 @@ # grunt-kmc | ||
## 视频示例 | ||
## 视频演示 | ||
@@ -29,2 +29,7 @@ - 生成依赖关系表:<http://asciinema.org/a/6731> | ||
构建规则说明:基于 [KISSY](http://docs.kissyui.com/) 的项目代码只要符合 [KMD](http://docs.kissyui.com/1.4/docs/html/guideline/kmd.html) 规范,在源码发布上线之前,要做至少两件事 | ||
1. 线上模块代码必须带有模块名配置 | ||
1. 静态合并或者生成依赖关系的Map | ||
## Gruntfile.js 里的 KMC 任务 | ||
@@ -75,3 +80,3 @@ | ||
KISSY 包配置项,比如: | ||
KISSY 包配置项,可以使用KISSY 1.2的数组方式,也可以使用KISSY 1.3+的对象方式。配置项的含义和KISSY的包配置规则完全一致,具体可参考[KISSY loader的文档](http://docs.kissyui.com/1.4/docs/html/api/loader/config.html)。比如: | ||
@@ -84,5 +89,14 @@ packages: [ | ||
ignorePackageNameInUri:true | ||
} | ||
] | ||
或者(推荐) | ||
packages: { | ||
'package-name': { | ||
base: './src/', | ||
charset:'utf-8', | ||
ignorePackageNameInUri:true | ||
} | ||
], | ||
} | ||
@@ -163,2 +177,3 @@ #### options.charset | ||
置为`true`时,会给所有文件补全模块名,建议当`comboOnly`为`true`时,总是设置此项为`true` | ||
重要:fixModuleName会在指定的src上进行补全模块名,所以如果您需要使用combo模式并且需要补全模块名,请先用grunt-contrib-copy将您的src文件拷贝到dest,然后再对dest执行kmc任务。 | ||
@@ -172,8 +187,111 @@ #### options.comboMap | ||
### options.copyAssets | ||
- 类型:`Boolean` | ||
- 默认值:`false` | ||
需要和fixModuleName搭配使用。 | ||
选项为true的时候,kmc会把src的文件拷贝到dest后再添加模块名。为false的时候,会直接在用户配置的src中的文件添加模块名。我们建议您如果有fixModuleName的需求的时候,先使用grunt-contrib-copy任务把src拷贝到dest,再执行grunt-kmc任务 | ||
---------------------------------- | ||
### 用法 | ||
## 用法 | ||
### 示例1,单文件静态合并 | ||
#### Example1 | ||
如果静态合并:其中`mods`中的文件被`index.js`和`list.js`所依赖,[Example](https://github.com/daxingplay/grunt-kmc/tree/master/example/combo-one-file) | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>Before</th> | ||
<th>After</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td> | ||
<pre> | ||
./src | ||
├── mods | ||
│ ├── a.js | ||
│ ├── b.js | ||
│ ├── c.js | ||
│ └── d.js | ||
└── pages | ||
└── home | ||
├── index.js | ||
└── list.js | ||
</pre> | ||
</td> | ||
<td> | ||
<pre> | ||
sample/build | ||
└── pages | ||
└── home | ||
├── index.js | ||
└── list.js | ||
</pre> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
#### Example2 | ||
生成Map:[Example](https://github.com/daxingplay/grunt-kmc/tree/master/example/generate-map-file) | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>Before</th> | ||
<th>After</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td> | ||
<pre> | ||
./src | ||
├── mods | ||
│ ├── a.js | ||
│ ├── b.js | ||
│ ├── c.js | ||
│ └── d.js | ||
└── pages | ||
└── home | ||
├── index.js | ||
└── list.js | ||
</pre> | ||
</td> | ||
<td> | ||
<pre> | ||
./build | ||
├── mods | ||
│ ├── a.js | ||
│ ├── b.js | ||
│ ├── c.js | ||
│ └── d.js | ||
├── map.js | ||
└── pages | ||
└── home | ||
├── index.js | ||
└── list.js | ||
</pre> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
#### Example3 | ||
仅补全模块名:[Example](https://github.com/daxingplay/grunt-kmc/tree/master/example/fix-module-only) | ||
------------------------------------------- | ||
### 更多配置写法参考 | ||
#### 示例1,单文件静态合并 | ||
入口为单个文件,将这个文件的依赖关系解析好后合并入另一个文件 | ||
@@ -189,3 +307,4 @@ | ||
path: 'assets/src', | ||
charset: 'utf-8' | ||
charset: 'utf-8', | ||
ignorePackageNameInUri:true | ||
} | ||
@@ -222,3 +341,3 @@ ] | ||
### 示例2,批量静态合并文件 | ||
#### 示例2,批量静态合并文件 | ||
@@ -258,3 +377,3 @@ 入口为一批文件,每个文件都解析合并 | ||
### 示例3,批量静态合并,报名为变量 | ||
#### 示例3,批量静态合并,包名为变量 | ||
@@ -272,3 +391,4 @@ 入口为一批文件,每个文件都解析合并,包名从配置文件中读取 | ||
path: '../', | ||
charset:'utf-8' | ||
charset:'utf-8', | ||
ignorePackageNameInUri:true | ||
} | ||
@@ -300,3 +420,3 @@ ], | ||
### 示例4,针对一批文件生成依赖关系表 | ||
#### 示例4,针对一批文件生成依赖关系表 | ||
@@ -331,10 +451,30 @@ 生成模块依赖关系表,同时源文件也被添加好模块名存放到目标目录 | ||
## 更多应用案例 | ||
### 更多应用案例 | ||
[Clam](http://github.com/jayli/generator-clam)工具和[ABC](http://abc.f2e.taobao.net/)依赖kmc。 | ||
--------------------------------------- | ||
## Q & A | ||
#### 生成的Map文件依赖地址怎么有绝对地址? | ||
比如 | ||
/*generated by KMC*/ | ||
KISSY.config('modules', { | ||
'xcake/app/cjs-full': { requires: ['node', '/home/bachi/xx/node-kpc/sample/src/components/header/index.js']}, | ||
'xcake/app/cjs': { requires: ['node', '/home/bachi/xx/node-kpc/sample/src/components/header/index.js']}, | ||
'xcake/app/fac-config': { requires: ['node']}, | ||
'xcake/app/namedMod2': { requires: ['node', '/home/bachi/xx/node-kpc/sample/src/app/mod.js']} | ||
}); | ||
原因是`header/index.js`文件不存在。 | ||
------------------------------------------- | ||
## Changelog | ||
* 0.1.15 bugfix for comboOnly & comboMap | ||
* 0.1.7 bugfix for comboMap | ||
* 0.1.6 add traverse option. | ||
* 0.1.5 fix charset output bug. |
@@ -28,3 +28,4 @@ /* | ||
depFileCharset = options.depFileCharset || options.charset, | ||
fixModuleName = options.fixModuleName !== false, | ||
fixModuleName = options.fixModuleName === true, | ||
fixModuleNameOnDest = options.copyAssets === true, | ||
traverse = options.traverse; | ||
@@ -57,3 +58,4 @@ | ||
if(comboOnly === true){ | ||
var r = kmc.combo(inputSrc, options.comboMap !== true ? depFile : undefined, depFileCharset, fixModuleName, true, grunt.file.isDir(outputSrc) ? outputSrc : path.dirname(outputSrc),comboOnly === true); | ||
var outputDir = grunt.file.isDir(outputSrc) ? outputSrc : path.dirname(outputSrc); | ||
var r = kmc.combo(inputSrc, options.comboMap !== true ? depFile : undefined, depFileCharset, fixModuleName, true, fixModuleNameOnDest ? outputDir : null,comboOnly === true); | ||
results.push(r); | ||
@@ -60,0 +62,0 @@ options.comboMap !== true && grunt.log.ok('Dep File "' + depFile + '" created.'); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36761
53
883
469
1