周末在家重构网关的Npm包,用到了rollup,记下笔记node
rollup适合库library的开发,而webpack适合应用程序的开发。 rollup也支持tree-shaking,自带的功能。 package.json 也具备 module 字段,像 Rollup 和 webpack 2 这样的 ES6 感知工具(ES6-aware tools)将会直接导入 ES6 模块版本。webpack
{
output: {
file: 'dist/index.umd.js',
format: 'umd',
name: 'ClientApi'
}
}
复制代码
rollup.config.js
git
$ rollup -c # compile
$ rollup -c -w # compile and watch
复制代码
rollup -w时,会抛出ROLLUP_WATCH环境变量为truegithub
{
"presets": [
["latest", {
"es2015": {
"modules": false
}
}]
],
"plugins": ["external-helpers"]
}
复制代码
咱们设置"modules": false,不然 Babel 会在 Rollup 有机会作处理以前,将咱们的模块转成 CommonJS,致使 Rollup 的一些处理失败。web