1
0

rollup.config.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import buble from '@rollup/plugin-buble'
  2. import replace from '@rollup/plugin-replace'
  3. import resolve from '@rollup/plugin-node-resolve'
  4. import commonjs from '@rollup/plugin-commonjs'
  5. import { terser } from 'rollup-plugin-terser'
  6. import pkg from './package.json'
  7. const banner = `/*!
  8. * vuex v${pkg.version}
  9. * (c) ${new Date().getFullYear()} Evan You
  10. * @license MIT
  11. */`
  12. const configs = [
  13. {
  14. input: 'src/index.js',
  15. file: 'dist/vuex.esm-browser.js',
  16. format: 'es',
  17. browser: true,
  18. env: 'development'
  19. },
  20. {
  21. input: 'src/index.js',
  22. file: 'dist/vuex.esm-browser.prod.js',
  23. format: 'es',
  24. browser: true,
  25. env: 'production'
  26. },
  27. {
  28. input: 'src/index.js',
  29. file: 'dist/vuex.esm-bundler.js',
  30. format: 'es',
  31. env: 'development'
  32. },
  33. {
  34. input: 'src/index.cjs.js',
  35. file: 'dist/vuex.global.js',
  36. format: 'iife',
  37. env: 'development'
  38. },
  39. {
  40. input: 'src/index.cjs.js',
  41. file: 'dist/vuex.global.prod.js',
  42. format: 'iife',
  43. minify: true,
  44. env: 'production'
  45. },
  46. {
  47. input: 'src/index.cjs.js',
  48. file: 'dist/vuex.cjs.js',
  49. format: 'cjs',
  50. env: 'development'
  51. }
  52. ]
  53. function createEntries() {
  54. return configs.map((c) => createEntry(c))
  55. }
  56. function createEntry(config) {
  57. const isGlobalBuild = config.format === 'iife'
  58. const isBundlerBuild = config.format !== 'iife' && !config.browser
  59. const isBundlerESMBuild = config.format === 'es' && !config.browser
  60. const c = {
  61. external: ['vue'],
  62. input: config.input,
  63. plugins: [],
  64. output: {
  65. banner,
  66. file: config.file,
  67. format: config.format,
  68. exports: 'auto',
  69. globals: {
  70. vue: 'Vue'
  71. }
  72. },
  73. onwarn: (msg, warn) => {
  74. if (!/Circular/.test(msg)) {
  75. warn(msg)
  76. }
  77. }
  78. }
  79. if (isGlobalBuild) {
  80. c.output.name = c.output.name || 'Vuex'
  81. }
  82. if (!isGlobalBuild) {
  83. c.external.push('@vue/devtools-api')
  84. }
  85. c.plugins.push(
  86. replace({
  87. preventAssignment: true,
  88. __VERSION__: pkg.version,
  89. __DEV__: isBundlerBuild
  90. ? `(process.env.NODE_ENV !== 'production')`
  91. : config.env !== 'production',
  92. __VUE_PROD_DEVTOOLS__: isBundlerESMBuild
  93. ? '__VUE_PROD_DEVTOOLS__'
  94. : 'false'
  95. })
  96. )
  97. if (config.transpile !== false) {
  98. c.plugins.push(
  99. buble({
  100. transforms: { asyncAwait: false, forOf: false }
  101. })
  102. )
  103. }
  104. c.plugins.push(resolve())
  105. c.plugins.push(commonjs())
  106. if (config.minify) {
  107. c.plugins.push(terser({ module: config.format === 'es' }))
  108. }
  109. return c
  110. }
  111. export default createEntries()