rollup.config.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. { input: 'src/index.js', file: 'dist/vuex.esm-browser.js', format: 'es', browser: true, env: 'development' },
  14. { input: 'src/index.js', file: 'dist/vuex.esm-browser.prod.js', format: 'es', browser: true, env: 'production' },
  15. { input: 'src/index.js', file: 'dist/vuex.esm-bundler.js', format: 'es', env: 'development' },
  16. { input: 'src/index.cjs.js', file: 'dist/vuex.global.js', format: 'iife', env: 'development' },
  17. { input: 'src/index.cjs.js', file: 'dist/vuex.global.prod.js', format: 'iife', minify: true, env: 'production' },
  18. { input: 'src/index.cjs.js', file: 'dist/vuex.cjs.js', format: 'cjs', env: 'development' }
  19. ]
  20. function createEntries() {
  21. return configs.map((c) => createEntry(c))
  22. }
  23. function createEntry(config) {
  24. const isGlobalBuild = config.format === 'iife'
  25. const isBundlerBuild = config.format !== 'iife' && !config.browser
  26. const isBundlerESMBuild = config.format === 'es' && !config.browser
  27. const c = {
  28. external: ['vue'],
  29. input: config.input,
  30. plugins: [],
  31. output: {
  32. banner,
  33. file: config.file,
  34. format: config.format,
  35. globals: {
  36. vue: 'Vue'
  37. }
  38. },
  39. onwarn: (msg, warn) => {
  40. if (!/Circular/.test(msg)) {
  41. warn(msg)
  42. }
  43. }
  44. }
  45. if (isGlobalBuild) {
  46. c.output.name = c.output.name || 'Vuex'
  47. }
  48. if (!isGlobalBuild) {
  49. c.external.push('@vue/devtools-api')
  50. }
  51. c.plugins.push(replace({
  52. preventAssignment: true,
  53. __VERSION__: pkg.version,
  54. __DEV__: isBundlerBuild
  55. ? `(process.env.NODE_ENV !== 'production')`
  56. : config.env !== 'production',
  57. __VUE_PROD_DEVTOOLS__: isBundlerESMBuild
  58. ? '__VUE_PROD_DEVTOOLS__'
  59. : 'false'
  60. }))
  61. if (config.transpile !== false) {
  62. c.plugins.push(buble())
  63. }
  64. c.plugins.push(resolve())
  65. c.plugins.push(commonjs())
  66. if (config.minify) {
  67. c.plugins.push(terser({ module: config.format === 'es' }))
  68. }
  69. return c
  70. }
  71. export default createEntries()