rollup.config.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. 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. __VERSION__: pkg.version,
  39. __DEV__: config.format !== 'iife' && !config.browser
  40. ? `(process.env.NODE_ENV !== 'production')`
  41. : config.env !== 'production'
  42. }))
  43. if (config.transpile !== false) {
  44. c.plugins.push(buble())
  45. }
  46. c.plugins.push(resolve())
  47. c.plugins.push(commonjs())
  48. if (config.minify) {
  49. c.plugins.push(terser({ module: config.format === 'es' }))
  50. }
  51. return c
  52. }