Rollup 是一个 JavaScript 模块打包器,能够将小块代码编译成大块复杂的代码,例如 library 或应用程序。shell
Rollup 对代码模块使用新的标准化格式,这些标准都包含在 JavaScript 的 ES6 版本中,而不是之前的特殊解决方案,如 CommonJS 和 AMD。ES6 模块能够使你自由、无缝地使用你最喜好的 library 中那些最有用独立函数,而你的项目没必要携带其余未使用的代码。ES6 模块最终仍是要由浏览器原生实现,但当前 Rollup 能够使你提早体验。npm
npm install rollup
建立rollup.config.js
文件并在packge.json
文件中增长如下命令
// rollup.config.js export default { input: 'src/main.js', output: { file: 'bundle.js', format: 'cjs' } };
{ "scripts": { "build": "rollup -c ../../rollup.config.js -w", }, }
--config | -c 指定配置文件地址
--wacth | -w 开启文件监视
https://www.rollupjs.com/guide/big-list-of-optionsjson
原文地址:https://kspf.xyz/archives/137/