rollup.config.mjs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 '../../shared/banner/index.mjs'
  8. const __dirname = path.dirname(fileURLToPath(import.meta.url))
  9. const ESM = process.env.ESM === 'true'
  10. const THEME = process.env.THEME === 'true'
  11. const external = []
  12. const plugins = [
  13. babel({
  14. exclude: 'node_modules/**',
  15. babelHelpers: 'bundled'
  16. })
  17. ]
  18. plugins.push(
  19. replace({
  20. 'process.env.NODE_ENV': '"production"',
  21. preventAssignment: true
  22. }),
  23. nodeResolve()
  24. )
  25. const destinationFile = `tabler${THEME ? '-theme' : ''}${ESM ? '.esm' : ''}`
  26. const rollupConfig = {
  27. input: path.resolve(__dirname, `../js/tabler${THEME ? '-theme' : ''}.js`),
  28. output: {
  29. banner: banner(),
  30. file: path.resolve(__dirname, `../dist/js/${destinationFile}.js`),
  31. format: ESM ? 'esm' : 'umd',
  32. generatedCode: 'es2015'
  33. },
  34. external,
  35. plugins
  36. }
  37. if (!ESM) {
  38. rollupConfig.output.name = `tabler${THEME ? '-theme' : ''}`
  39. }
  40. export default rollupConfig