一谆沃、安裝
npm install rollup --global
安裝成功后锯岖,在命令行窗口中介袜,輸入:
rollup
會看到關(guān)于 rollup 幫助信息
二、命令解釋
rollup src/main.js
打包文件出吹,會把打包后的文件輸出出來
rollup src/main.js --output bundle.js
打包文件遇伞,并輸出到 bundle.js
rollup src/main.js --output bundle.js --format cjs
# rollup src/main.js -o bundle.js -f cjs
以commonjs 的方式打包文件
三、使用配置文件
- 創(chuàng)建 rollup.config.js:
export default {
entry: 'src/main.js',
format: 'cjs',
dest: 'bundle.js' // equivalent to --output
};
- 執(zhí)行命令:
rollup -c
# rollup -c -o bundle-2.js
-o 可以重寫部分選項
- 在開發(fā)環(huán)境和生產(chǎn)環(huán)境捶牢,執(zhí)行不同的config
rollup --config rollup.config.dev.js
rollup --config rollup.config.prod.js