rollup-plugins.mjs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { visualizer } from 'rollup-plugin-visualizer'
  2. import license from 'rollup-plugin-license'
  3. import esbuild from 'rollup-plugin-esbuild'
  4. const getRollupPlugins = (pkg, minify) => {
  5. return [
  6. esbuild({
  7. minify
  8. }),
  9. license({
  10. banner: `@license ${pkg.name} v${pkg.version} - ${pkg.license}
  11. This source code is licensed under the ${pkg.license} license.
  12. See the LICENSE file in the root directory of this source tree.`
  13. }),
  14. visualizer({
  15. sourcemap: false,
  16. filename: `stats/${pkg.name}${minify ? '-min' : ''}.html`
  17. })
  18. ].filter(Boolean)
  19. }
  20. export const getRollupConfig = (pkg, outputFileName, bundles, globals) => {
  21. return bundles
  22. .map(({ inputs, format, minify, preserveModules, outputDir = 'dist', extension = 'js', exports = 'named' }) => {
  23. return inputs.map(input => ({
  24. input,
  25. plugins: getRollupPlugins(pkg, minify),
  26. external: Object.keys(globals),
  27. output: {
  28. name: pkg.name,
  29. ...(preserveModules
  30. ? {
  31. dir: `${outputDir}/${format}`,
  32. entryFileNames: `[name].${extension}`,
  33. }
  34. : {
  35. file: `${outputDir}/${format}/${outputFileName}${minify ? '.min' : ''}.${extension}`,
  36. }),
  37. format,
  38. sourcemap: true,
  39. preserveModules,
  40. preserveModulesRoot: 'src',
  41. exports,
  42. globals,
  43. },
  44. }))
  45. })
  46. .flat();
  47. }