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