rollup.config.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import replace from '@rollup/plugin-replace'
  2. import resolve from '@rollup/plugin-node-resolve'
  3. import commonjs from '@rollup/plugin-commonjs'
  4. import { terser } from 'rollup-plugin-terser'
  5. import pkg from './package.json'
  6. const banner = `/*!
  7. /**
  8. * vuex v${pkg.version}
  9. * (c) ${new Date().getFullYear()} Evan You
  10. * @license MIT
  11. */`
  12. export function createEntries(configs) {
  13. return configs.map((c) => createEntry(c))
  14. }
  15. function createEntry(config) {
  16. const c = {
  17. external: ['vue'],
  18. input: config.input,
  19. plugins: [],
  20. output: {
  21. banner,
  22. file: config.file,
  23. format: config.format,
  24. globals: {
  25. vue: 'Vue'
  26. }
  27. },
  28. onwarn: (msg, warn) => {
  29. if (!/Circular/.test(msg)) {
  30. warn(msg)
  31. }
  32. }
  33. }
  34. if (config.format === 'iife' || config.format === 'umd') {
  35. c.output.name = c.output.name || 'Vuex'
  36. }
  37. c.plugins.push(replace({
  38. __DEV__: config.format === 'es' && !config.browser
  39. ? `(process.env.NODE_ENV !== 'production')`
  40. : config.env !== 'production'
  41. }))
  42. c.plugins.push(resolve())
  43. c.plugins.push(commonjs())
  44. if (config.minify) {
  45. c.plugins.push(terser({ module: config.format === 'es' }))
  46. }
  47. return c
  48. }