config.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 weexVersion = process.env.WEEX_VERSION || require('../packages/weex-vue-framework/package.json').version
  8. const banner =
  9. '/*!\n' +
  10. ' * Vue.js v' + version + '\n' +
  11. ' * (c) 2014-' + new Date().getFullYear() + ' Evan You\n' +
  12. ' * Released under the MIT License.\n' +
  13. ' */'
  14. const builds = {
  15. // Runtime only (CommonJS). Used by bundlers e.g. Webpack & Browserify
  16. 'web-runtime-cjs': {
  17. entry: path.resolve(__dirname, '../src/entries/web-runtime.js'),
  18. dest: path.resolve(__dirname, '../dist/vue.runtime.common.js'),
  19. format: 'cjs',
  20. banner
  21. },
  22. // Runtime+compiler CommonJS build (CommonJS)
  23. 'web-full-cjs': {
  24. entry: path.resolve(__dirname, '../src/entries/web-runtime-with-compiler.js'),
  25. dest: path.resolve(__dirname, '../dist/vue.common.js'),
  26. format: 'cjs',
  27. alias: { he: './entity-decoder' },
  28. banner
  29. },
  30. // runtime-only build (Browser)
  31. 'web-runtime-dev': {
  32. entry: path.resolve(__dirname, '../src/entries/web-runtime.js'),
  33. dest: path.resolve(__dirname, '../dist/vue.runtime.js'),
  34. format: 'umd',
  35. env: 'development',
  36. banner
  37. },
  38. // runtime-only production build (Browser)
  39. 'web-runtime-prod': {
  40. entry: path.resolve(__dirname, '../src/entries/web-runtime.js'),
  41. dest: path.resolve(__dirname, '../dist/vue.runtime.min.js'),
  42. format: 'umd',
  43. env: 'production',
  44. banner
  45. },
  46. // Runtime+compiler development build (Browser)
  47. 'web-full-dev': {
  48. entry: path.resolve(__dirname, '../src/entries/web-runtime-with-compiler.js'),
  49. dest: path.resolve(__dirname, '../dist/vue.js'),
  50. format: 'umd',
  51. env: 'development',
  52. alias: { he: './entity-decoder' },
  53. banner
  54. },
  55. // Runtime+compiler production build (Browser)
  56. 'web-full-prod': {
  57. entry: path.resolve(__dirname, '../src/entries/web-runtime-with-compiler.js'),
  58. dest: path.resolve(__dirname, '../dist/vue.min.js'),
  59. format: 'umd',
  60. env: 'production',
  61. alias: { he: './entity-decoder' },
  62. banner
  63. },
  64. // Web compiler (CommonJS).
  65. 'web-compiler': {
  66. entry: path.resolve(__dirname, '../src/entries/web-compiler.js'),
  67. dest: path.resolve(__dirname, '../packages/vue-template-compiler/build.js'),
  68. format: 'cjs',
  69. external: ['he', 'de-indent']
  70. },
  71. // Web server renderer (CommonJS).
  72. 'web-server-renderer': {
  73. entry: path.resolve(__dirname, '../src/entries/web-server-renderer.js'),
  74. dest: path.resolve(__dirname, '../packages/vue-server-renderer/build.js'),
  75. format: 'cjs',
  76. external: ['stream', 'module', 'vm', 'he', 'de-indent']
  77. },
  78. // Weex runtime framework (CommonJS).
  79. 'weex-framework': {
  80. weex: true,
  81. entry: path.resolve(__dirname, '../src/entries/weex-framework.js'),
  82. dest: path.resolve(__dirname, '../packages/weex-vue-framework/index.js'),
  83. format: 'cjs'
  84. },
  85. // Weex compiler (CommonJS). Used by Weex's Webpack loader.
  86. 'weex-compiler': {
  87. weex: true,
  88. entry: path.resolve(__dirname, '../src/entries/weex-compiler.js'),
  89. dest: path.resolve(__dirname, '../packages/weex-template-compiler/build.js'),
  90. format: 'cjs',
  91. external: ['he', 'de-indent']
  92. }
  93. }
  94. function genConfig (opts) {
  95. const config = {
  96. entry: opts.entry,
  97. dest: opts.dest,
  98. external: opts.external,
  99. format: opts.format,
  100. banner: opts.banner,
  101. moduleName: 'Vue',
  102. plugins: [
  103. replace({
  104. __WEEX__: !!opts.weex,
  105. __WEEX_VERSION__: weexVersion,
  106. __VERSION__: version
  107. }),
  108. flow(),
  109. buble(),
  110. alias(Object.assign({}, require('./alias'), opts.alias))
  111. ]
  112. }
  113. if (opts.env) {
  114. config.plugins.push(replace({
  115. 'process.env.NODE_ENV': JSON.stringify(opts.env)
  116. }))
  117. }
  118. return config
  119. }
  120. if (process.env.TARGET) {
  121. module.exports = genConfig(builds[process.env.TARGET])
  122. } else {
  123. exports.getBuild = name => genConfig(builds[name])
  124. exports.getAllBuilds = () => Object.keys(builds).map(name => genConfig(builds[name]))
  125. }