config.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 builds = {
  14. // Runtime only (CommonJS). Used by bundlers e.g. Webpack & Browserify
  15. 'web-runtime-dev': {
  16. entry: path.resolve(__dirname, '../src/entries/web-runtime.js'),
  17. dest: path.resolve(__dirname, '../dist/vue.common.js'),
  18. format: 'cjs',
  19. banner
  20. },
  21. // runtime-only build for CDN
  22. 'web-runtime-cdn-dev': {
  23. entry: path.resolve(__dirname, '../src/entries/web-runtime.js'),
  24. dest: path.resolve(__dirname, '../dist/vue.runtime.js'),
  25. format: 'umd',
  26. banner
  27. },
  28. // runtime-only production build for CDN
  29. 'web-runtime-cdn-prod': {
  30. entry: path.resolve(__dirname, '../src/entries/web-runtime.js'),
  31. dest: path.resolve(__dirname, '../dist/vue.runtime.min.js'),
  32. format: 'umd',
  33. env: 'production',
  34. banner
  35. },
  36. // Runtime+compiler standalone development build.
  37. 'web-standalone-dev': {
  38. entry: path.resolve(__dirname, '../src/entries/web-runtime-with-compiler.js'),
  39. dest: path.resolve(__dirname, '../dist/vue.js'),
  40. format: 'umd',
  41. env: 'development',
  42. banner
  43. },
  44. // Runtime+compiler standalone production build.
  45. 'web-standalone-prod': {
  46. entry: path.resolve(__dirname, '../src/entries/web-runtime-with-compiler.js'),
  47. dest: path.resolve(__dirname, '../dist/vue.min.js'),
  48. format: 'umd',
  49. env: 'production',
  50. banner
  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: ['he', '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', 'he', '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(require('./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. }