gulp-moder
Gulp plugin for Moder.js
前端模块加载器 Moder.js 构建工具,辅助自动生成模块 Map。
使用方法
安装命令:
$ npm install gulp-moder --save-dev
Gulp 任务配置 Gulpfile.js
:
/** * Gulp.js 构建文件 * * @author Pandao * @updateTime 2016-04-17 */ var fs = ;var gulp = ;var clean = ;var notify = ;var uglify = ;var rename = ;var conact = ;var replace = ;var header = ;var moder = ; // 定义源文件目录modersrcPath = "./modules/"; // 定义目标输出目录moderdestPath = "./output/"; /** * 打包一个包模块文件,即一个文件中有多个 define */ gulp; /** * 清空目标输出目录 */ gulp; /** * 自动加模块名和生成模块 Map */ gulp; gulp; gulp;
标签语法:
用于自动生成模块 Map,注意标签必须靠左边顶格写(左边无空格)。
1、单文件单个模块
//@moduleName xxxx // 模块名//@moduleDeps xxx,xxx,... // 模块依赖 ;
在
define
内通过require.async('xxx', function(){//...});
方式调用的模块不需要定义在//@moduleDeps
模块依赖中。
2、包模块文件,即一个文件内有多个模块 define
//@modulePackage xxxx // 包名 //@moduleName xxxx // 模块名//@moduleDeps xxx,xxx,... // 模块依赖 ; //@moduleName xxxx // 模块名//@moduleDeps xxx,xxx,... // 模块依赖 ; //@moduleName xxxx // 模块名//@moduleDeps xxx,xxx,... // 模块依赖 ;
生成结果:
./output
/pkg
all_3aa20277.js
pkg2_d3903ca2.js
/c
main_2f3dd68c.js
/view
info_fd175e15.js
...
/component
cart.list_707594a1.js
...
...
当配置项
versionQuery = true
(v0.1.4 起新增,默认为true
) 且不调用moder.rename()
方法时,模块文件的 URL 形式为/component/cart.list.js?v=707594a1
,用于保证文件始终存在,避免无法请求到文件。
调用模块:
;
License
The MIT license.
Copyright (c) 2016 Pandao