undefined
前言
Compile small pieces of code into something larger and more complex(官网)
下载依赖
通过命令行参数打包JS文件
-o src/main.js:指定输出文件路径
-f:转换输出格式
-f umd --name <name>:通用环境,通过--name <name>指定在浏览器环境中的全局变量名
-f cjs:CommonJS环境
-f iife:浏览器环境,需要手动修改最后一行})({})改为})(this)或})(window)
-f amd:AMD环境
1
| rollup src/main.js -o dist/bundle.js
|
通过配置文件打包JS文件
修改配置文件
rollup.config.js1 2 3 4 5 6 7 8
| module.exports = { input: "src/main.js", output: { file: "dist/bundle.js", format: "umd", name: "<name>" } }
|
打包为多个JS文件
rollup.config.js1 2 3 4 5 6 7 8 9 10 11 12 13 14
| module.exports = { input: "src/main.js", output: [ { file: "dist/bundle.js", format: "umd", name: "<name>" }, { file: "dist/bundle.cjs", format: "cjs" } ] }
|
打包JS文件
完成