rollup.config.mjs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import path from 'node:path'
  2. import process from 'node:process'
  3. import { fileURLToPath } from 'node:url'
  4. import { babel } from '@rollup/plugin-babel'
  5. import { nodeResolve } from '@rollup/plugin-node-resolve'
  6. import replace from '@rollup/plugin-replace'
  7. import banner from './banner.mjs'
  8. const __dirname = path.dirname(fileURLToPath(import.meta.url))
  9. const BUNDLE = process.env.BUNDLE === 'true'
  10. const ESM = process.env.ESM === 'true'
  11. let destinationFile = `tabler${ESM ? '.esm' : ''}`
  12. const external = ['@popperjs/core', 'bootstrap']
  13. const plugins = [
  14. babel({
  15. exclude: 'node_modules/**',
  16. babelHelpers: 'bundled'
  17. })
  18. ]
  19. const globals = {
  20. '@popperjs/core': 'Popper',
  21. 'bootstrap': 'Bootstrap',
  22. }
  23. if (BUNDLE) {
  24. destinationFile += '.bundle'
  25. external.pop()
  26. external.pop()
  27. delete globals['@popperjs/core']
  28. delete globals['bootstrap']
  29. plugins.push(
  30. replace({
  31. 'process.env.NODE_ENV': '"production"',
  32. preventAssignment: true
  33. }),
  34. nodeResolve()
  35. )
  36. }
  37. const rollupConfig = {
  38. input: path.resolve(__dirname, `../js/index.${ESM ? 'esm' : 'umd'}.js`),
  39. output: {
  40. banner: banner(),
  41. file: path.resolve(__dirname, `../dist/js/${destinationFile}.js`),
  42. format: ESM ? 'esm' : 'umd',
  43. globals,
  44. generatedCode: 'es2015'
  45. },
  46. external,
  47. plugins
  48. }
  49. if (!ESM) {
  50. rollupConfig.output.name = 'tabler'
  51. }
  52. export default rollupConfig