rollup.config.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. 'use strict'
  2. const path = require('path')
  3. const { babel } = require('@rollup/plugin-babel')
  4. const { nodeResolve } = require('@rollup/plugin-node-resolve')
  5. const replace = require('@rollup/plugin-replace')
  6. const banner = require('./banner.js')
  7. const BUNDLE = process.env.BUNDLE === 'true'
  8. const ESM = process.env.ESM === 'true'
  9. let fileDest = `bootstrap${ESM ? '.esm' : ''}`
  10. const external = ['@popperjs/core']
  11. const plugins = [
  12. babel({
  13. // Only transpile our source code
  14. exclude: 'node_modules/**',
  15. // Include the helpers in the bundle, at most one copy of each
  16. babelHelpers: 'bundled'
  17. })
  18. ]
  19. const globals = {
  20. '@popperjs/core': 'Popper'
  21. }
  22. if (BUNDLE) {
  23. fileDest += '.bundle'
  24. // Remove last entry in external array to bundle Popper
  25. external.pop()
  26. delete globals['@popperjs/core']
  27. plugins.push(
  28. replace({
  29. 'process.env.NODE_ENV': '"production"',
  30. preventAssignment: true
  31. }),
  32. nodeResolve()
  33. )
  34. }
  35. const rollupConfig = {
  36. input: path.resolve(__dirname, `../js/index.${ESM ? 'esm' : 'umd'}.js`),
  37. output: {
  38. banner,
  39. file: path.resolve(__dirname, `../dist/js/${fileDest}.js`),
  40. format: ESM ? 'esm' : 'umd',
  41. globals
  42. },
  43. external,
  44. plugins
  45. }
  46. if (!ESM) {
  47. rollupConfig.output.name = 'bootstrap'
  48. }
  49. module.exports = rollupConfig