config.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. const path = require('path')
  2. const flow = require('rollup-plugin-flow-no-whitespace')
  3. const buble = require('rollup-plugin-buble')
  4. const replace = require('rollup-plugin-replace')
  5. const alias = require('rollup-plugin-alias')
  6. const version = process.env.VERSION || require('../package.json').version
  7. const banner =
  8. '/*!\n' +
  9. ' * Vue.js v' + version + '\n' +
  10. ' * (c) 2014-' + new Date().getFullYear() + ' Evan You\n' +
  11. ' * Released under the MIT License.\n' +
  12. ' */'
  13. const baseAlias = require('./alias')
  14. const builds = {
  15. // Runtime only (CommonJS). Used by bundlers e.g. Webpack & Browserify
  16. 'web-runtime-dev': {
  17. entry: path.resolve(__dirname, '../src/entries/web-runtime.js'),
  18. dest: path.resolve(__dirname, '../dist/vue.common.js'),
  19. format: 'cjs',
  20. banner
  21. },
  22. // Minified runtime, only for filze size monitoring
  23. 'web-runtime-prod': {
  24. entry: path.resolve(__dirname, '../src/entries/web-runtime.js'),
  25. dest: path.resolve(__dirname, '../dist/vue.common.min.js'),
  26. format: 'umd',
  27. env: 'production',
  28. banner
  29. },
  30. // Runtime+compiler standalone developement build.
  31. 'web-standalone-dev': {
  32. entry: path.resolve(__dirname, '../src/entries/web-runtime-with-compiler.js'),
  33. dest: path.resolve(__dirname, '../dist/vue.js'),
  34. format: 'umd',
  35. env: 'development',
  36. banner,
  37. alias: {
  38. entities: './entity-decoder'
  39. }
  40. },
  41. // Runtime+compiler standalone production build.
  42. 'web-standalone-prod': {
  43. entry: path.resolve(__dirname, '../src/entries/web-runtime-with-compiler.js'),
  44. dest: path.resolve(__dirname, '../dist/vue.min.js'),
  45. format: 'umd',
  46. env: 'production',
  47. banner,
  48. alias: {
  49. entities: './entity-decoder'
  50. }
  51. },
  52. // Web compiler (CommonJS).
  53. 'web-compiler': {
  54. entry: path.resolve(__dirname, '../src/entries/web-compiler.js'),
  55. dest: path.resolve(__dirname, '../packages/vue-template-compiler/build.js'),
  56. format: 'cjs',
  57. external: ['entities', 'de-indent']
  58. },
  59. // Web server renderer (CommonJS).
  60. 'web-server-renderer': {
  61. entry: path.resolve(__dirname, '../src/entries/web-server-renderer.js'),
  62. dest: path.resolve(__dirname, '../packages/vue-server-renderer/build.js'),
  63. format: 'cjs',
  64. external: ['stream', 'module', 'vm', 'entities', 'de-indent']
  65. }
  66. }
  67. function genConfig (opts) {
  68. const config = {
  69. entry: opts.entry,
  70. dest: opts.dest,
  71. external: opts.external,
  72. format: opts.format,
  73. banner: opts.banner,
  74. moduleName: 'Vue',
  75. plugins: [
  76. flow(),
  77. buble(),
  78. alias(Object.assign({}, baseAlias, opts.alias))
  79. ]
  80. }
  81. if (opts.env) {
  82. config.plugins.push(replace({
  83. 'process.env.NODE_ENV': JSON.stringify(opts.env),
  84. 'process.env.VUE_ENV': JSON.stringify('client')
  85. }))
  86. }
  87. return config
  88. }
  89. if (process.env.TARGET) {
  90. module.exports = genConfig(builds[process.env.TARGET])
  91. } else {
  92. exports.getBuild = name => genConfig(builds[name])
  93. exports.getAllBuilds = () => Object.keys(builds).map(name => genConfig(builds[name]))
  94. }