rollup -w -c scripts/config.js --environment TARGET:web-full-dev
-c
指定配置文件-w
监听文件,文件发生改变时重新构建--environment
设置环境变量。如rollup -c --environment TARGET:web-full-dev
可以通过process.env.TARGET
获取
if (process.env.TARGET) { // 根据TARGET生成rollup config对象 module.exports = genConfig(process.env.TARGET) //生成rollup config对象} else { //如果没有设置TARGET,返回生成函数 exports.getBuild = genConfig exports.getAllBuilds = () => Object.keys(builds).map(genConfig)}
rollup -w -c scripts/config.js --environment TARGET:web-full-dev
对应rollup config对象如下:
{ input: opts.entry, //入口 src/platforms/web/entry-runtime-with-compiler.js external: opts.external, plugins: [ flow(), alias(Object.assign({}, aliases, { he: './entity-decoder' })) ].concat(opts.plugins || []), output: { file: resolve('dist/vue.js'), format: 'umd', // umd – 通用模块定义,以amd,cjs 和 iife 为一体 banner: opts.banner, name: opts.moduleName || 'Vue' }, onwarn: (msg, warn) => { //拦截警告信息 if (!/Circular/.test(msg)) { warn(msg) } }}
- rollup-plugin-flow-no-whitespace //去除flow静态类型检查代码
- rollup-plugin-alias //为模块提供别名
- rollup-plugin-buble //编译ES6+语法为ES2015,无需配置,比babel更轻量
- rollup-plugin-replace //替换代码中的变量为指定值
参考资料:
1、rollup文档