grunt-spm-server
A Grunt task plugin, transport
CommonJS
module dynamically forSeaJS
environment.
Grunt 插件:通过 Web 服务实时地转换 CommonJS 模块以方便 SeaJS 环境中的开发调试。
背景
- SPM 版本从 2 升级到 3,遵循的规范从 CMD 转为 CommonJS;
- 前端开发调试过程中需要对 CommonJS 模块动态 Wrapping;
- 纯前端的解决方案 seajs-wrap 存在不少弊端。
用法
$ npm install --save-dev grunt-spm-server
grunt;
$ grunt server:develop$ grunt server:release
参数
src
Type: `Array | String`
config 文件模板路径,可选。
dest
Type: `String`
config 文件存放路径,可选,默认 `'lib/config.js'`。
options.api
Type: `String`
API mocking 文件存放目录。
// json "/url/to/foo": "POST": "code": 0 "message": "POST ok" "notice_id": "xxxxxxx" "PATCH": "code": 0 "message": "PATCH ok" "notice_id": "xxxxxxx" "/url/to/bar": // asterisk match any RESTful request method "*": "code": 0 "message": "ok" // or jsmoduleexports = '/foo/bar': // function is support { return 'MOCKAPI': // means redirect 'status': '302' 'location': '/foo/bar' + query1 + '.png' ; } ;
options.base
Type: `String`
Default value: `'.'`
Web 服务根目录。
options.config
Type: `Boolean`
Default value: `true`
是否生成 config 文件。
options.port
Type: `Number`
Default value: `8851`
Web 服务侦听端口。
options.release
Type: `Boolean`
Default value: `true`
是否模拟线上环境,为 `true` 则不执行服务端 wrapping。
options.rule
Type: `Function | RegExp`
路径匹配函数,可选,返回 `true` 则执行服务端 wrapping。
{ if query !== -1 return false; if idleading if idleading !== -1 url = url; else if url !== -1 url = url; // 默认匹配 return /^\/\.$/;} // or RegExp/^\/\.$/