rollup.config.mjs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import svelte from 'rollup-plugin-svelte';
  2. import resolve from '@rollup/plugin-node-resolve';
  3. import svelteConfig from './svelte.config.mjs';
  4. import fs from 'fs'
  5. import { getRollupPlugins } from '../../.build/build-icons.mjs'
  6. const pkg = JSON.parse(fs.readFileSync('package.json', 'utf-8'))
  7. const packageName = '@tabler/icons-svelte';
  8. const outputFileName = 'tabler-icons-svelte';
  9. const outputDir = 'dist';
  10. const inputs = ['./src/tabler-icons-svelte.js'];
  11. const bundles = [
  12. {
  13. format: 'es',
  14. inputs,
  15. outputDir,
  16. },
  17. {
  18. format: 'esm',
  19. inputs,
  20. outputDir,
  21. preserveModules: true,
  22. },
  23. {
  24. format: 'svelte',
  25. inputs,
  26. outputDir,
  27. preserveModules: true,
  28. },
  29. ];
  30. const configs = bundles
  31. .map(({ inputs, outputDir, format, minify, preserveModules }) =>
  32. inputs.map(input => ({
  33. input,
  34. plugins: [
  35. ...(format !== 'svelte' ? [
  36. svelte({
  37. ...svelteConfig,
  38. include: 'src/**/*.svelte',
  39. compilerOptions: {
  40. dev: false,
  41. css: false,
  42. hydratable: true,
  43. },
  44. emitCss: false,
  45. }),
  46. resolve({
  47. browser: true,
  48. exportConditions: ['svelte'],
  49. extensions: ['.svelte']
  50. }),
  51. ] : []),
  52. ...getRollupPlugins(pkg, minify),
  53. ],
  54. external: format === 'svelte' ? [/\.svelte/] : ['svelte'],
  55. output: {
  56. name: packageName,
  57. ...(preserveModules
  58. ? {
  59. dir: `${outputDir}/${format}`,
  60. }
  61. : {
  62. file: `${outputDir}/${format}/${outputFileName}${minify ? '.min' : ''}.js`,
  63. }),
  64. preserveModules,
  65. format: format === 'svelte' ? 'esm' : format,
  66. sourcemap: true,
  67. globals: {
  68. svelte: 'svelte',
  69. },
  70. },
  71. })),
  72. )
  73. .flat();
  74. export default configs;