| 1 | import terser from '@rollup/plugin-terser' |
| 2 | import typescript from '@rollup/plugin-typescript' |
| 3 | import analyze from 'rollup-plugin-analyzer' |
| 4 | import command from 'rollup-plugin-command' |
| 5 | import del from 'rollup-plugin-delete' |
| 6 | |
| 7 | const isDevelopmentBuild = process.env.BUILD === 'development' |
| 8 | const isAnalyze = process.env.ANALYZE |
| 9 | const isDocumentation = process.env.DOCUMENTATION |
| 10 | |
| 11 | export default { |
| 12 | input: 'src/index.ts', |
| 13 | strictDeprecations: true, |
| 14 | output: [ |
| 15 | { |
| 16 | ...(isDevelopmentBuild ? { dir: 'lib' } : { file: 'lib/index.js' }), |
| 17 | format: 'cjs', |
| 18 | sourcemap: !!isDevelopmentBuild, |
| 19 | ...(isDevelopmentBuild && { |
| 20 | preserveModules: true, |
| 21 | preserveModulesRoot: 'src' |
| 22 | }), |
| 23 | ...(!isDevelopmentBuild && { plugins: [terser({ maxWorkers: 2 })] }) |
| 24 | }, |
| 25 | { |
| 26 | ...(isDevelopmentBuild ? { dir: 'lib' } : { file: 'lib/index.mjs' }), |
| 27 | format: 'esm', |
| 28 | sourcemap: !!isDevelopmentBuild, |
| 29 | ...(isDevelopmentBuild && { |
| 30 | entryFileNames: '[name].mjs', |
| 31 | preserveModules: true, |
| 32 | preserveModulesRoot: 'src' |
| 33 | }), |
| 34 | ...(!isDevelopmentBuild && { plugins: [terser({ maxWorkers: 2 })] }) |
| 35 | } |
| 36 | ], |
| 37 | external: ['async_hooks', 'cluster', 'events', 'os', 'worker_threads'], |
| 38 | plugins: [ |
| 39 | typescript({ |
| 40 | tsconfig: isDevelopmentBuild |
| 41 | ? 'tsconfig.development.json' |
| 42 | : 'tsconfig.production.json' |
| 43 | }), |
| 44 | del({ |
| 45 | targets: ['lib/*'] |
| 46 | }), |
| 47 | isAnalyze && analyze(), |
| 48 | isDocumentation && command('pnpm run typedoc') |
| 49 | ] |
| 50 | } |