babel-plugin-demand
用于公共 js 库按需加载的babel插件
Install
npm i babel-plugin-demand -D
Usage
在 .babelrc
或者 babel-loader 文件中配置
"plugins": "demand" packageName: 'xx-sdk' redirect: 'lib' // ...options
Example
上述代码会被转为
options
参数名称 | 类型 | 含义 | 是否必填 | 默认值 |
---|---|---|---|---|
packageName | String | js 包的名字 | 是 | 无 |
redirect | String | 函数所在的目录 | 否 | 'lib' |
moreRedirect | Array | 当redirect 目录不存在时,自动检索该数组中的路径 |
否 | [] |
camel2Dash | Boolean | 驼峰文件名是否需要转为'-'连接 | 否 | false |
more
- 编译过程中 ast 的 types 可以参考doc文件下的 ast-types