config.js 4.5 KB

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