VUE2610scriptsconfigjs

33次阅读

共计 1033 个字符,预计需要花费 3 分钟才能阅读完成。

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 文档

正文完
 0