rollup.config.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 c = {
  27. external: ['vue'],
  28. input: config.input,
  29. plugins: [],
  30. output: {
  31. banner,
  32. file: config.file,
  33. format: config.format,
  34. globals: {
  35. vue: 'Vue'
  36. }
  37. },
  38. onwarn: (msg, warn) => {
  39. if (!/Circular/.test(msg)) {
  40. warn(msg)
  41. }
  42. }
  43. }
  44. if (isGlobalBuild) {
  45. c.output.name = c.output.name || 'Vuex'
  46. }
  47. if (!isGlobalBuild) {
  48. c.external.push('@vue/devtools-api')
  49. }
  50. c.plugins.push(replace({
  51. preventAssignment: true,
  52. __VERSION__: pkg.version,
  53. __DEV__: isBundlerBuild
  54. ? `(process.env.NODE_ENV !== 'production')`
  55. : config.env !== 'production',
  56. __VUE_PROD_DEVTOOLS__: isBundlerBuild ? '__VUE_PROD_DEVTOOLS__' : 'false'
  57. }))
  58. if (config.transpile !== false) {
  59. c.plugins.push(buble())
  60. }
  61. c.plugins.push(resolve())
  62. c.plugins.push(commonjs())
  63. if (config.minify) {
  64. c.plugins.push(terser({ module: config.format === 'es' }))
  65. }
  66. return c
  67. }
  68. export default createEntries()