config.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. },
  21. // Minified runtime, only for filze size monitoring
  22. 'web-runtime-prod': {
  23. entry: path.resolve(__dirname, '../src/entries/web-runtime.js'),
  24. dest: path.resolve(__dirname, '../dist/vue.common.min.js'),
  25. format: 'umd',
  26. env: 'production'
  27. },
  28. // Runtime+compiler standalone developement build.
  29. 'web-standalone-dev': {
  30. entry: path.resolve(__dirname, '../src/entries/web-runtime-with-compiler.js'),
  31. dest: path.resolve(__dirname, '../dist/vue.js'),
  32. format: 'umd',
  33. env: 'development',
  34. banner,
  35. alias: {
  36. entities: './entity-decoder'
  37. }
  38. },
  39. // Runtime+compiler standalone production build.
  40. 'web-standalone-prod': {
  41. entry: path.resolve(__dirname, '../src/entries/web-runtime-with-compiler.js'),
  42. dest: path.resolve(__dirname, '../dist/vue.min.js'),
  43. format: 'umd',
  44. env: 'production',
  45. banner,
  46. alias: {
  47. entities: './entity-decoder'
  48. }
  49. },
  50. // Web compiler (CommonJS).
  51. 'web-compiler': {
  52. entry: path.resolve(__dirname, '../src/entries/web-compiler.js'),
  53. dest: path.resolve(__dirname, '../packages/vue-template-compiler/build.js'),
  54. format: 'cjs',
  55. external: ['entities', 'de-indent']
  56. },
  57. // Web server renderer (CommonJS).
  58. 'web-server-renderer': {
  59. entry: path.resolve(__dirname, '../src/entries/web-server-renderer.js'),
  60. dest: path.resolve(__dirname, '../packages/vue-server-renderer/build.js'),
  61. format: 'cjs',
  62. external: ['stream', 'module', 'vm', 'entities', 'de-indent']
  63. }
  64. }
  65. function genConfig (opts) {
  66. const config = {
  67. entry: opts.entry,
  68. dest: opts.dest,
  69. external: opts.external,
  70. format: opts.format,
  71. banner: opts.banner,
  72. moduleName: 'Vue',
  73. plugins: [
  74. flow(),
  75. buble(),
  76. alias(Object.assign({}, baseAlias, opts.alias))
  77. ]
  78. }
  79. if (opts.env) {
  80. config.plugins.push(replace({
  81. 'process.env.NODE_ENV': JSON.stringify(opts.env),
  82. 'process.env.VUE_ENV': JSON.stringify('client')
  83. }))
  84. }
  85. return config
  86. }
  87. if (process.env.TARGET) {
  88. module.exports = genConfig(builds[process.env.TARGET])
  89. } else {
  90. exports.getBuild = name => genConfig(builds[name])
  91. exports.getAllBuilds = () => Object.keys(builds).map(name => genConfig(builds[name]))
  92. }