build: refactor build options handling
[poolifier.git] / rollup.config.mjs
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 isAnalyzeBuild = process.env.ANALYZE
9 const isDocumentationBuild = process.env.DOCUMENTATION
10
11 export default {
12 input: 'src/index.ts',
13 strictDeprecations: true,
14 output: [
15 {
16 format: 'cjs',
17 sourcemap: !!isDevelopmentBuild,
18 ...(isDevelopmentBuild && {
19 dir: 'lib',
20 preserveModules: true,
21 preserveModulesRoot: 'src'
22 }),
23 ...(!isDevelopmentBuild && {
24 file: 'lib/index.js',
25 plugins: [terser({ maxWorkers: 2 })]
26 })
27 },
28 {
29 format: 'esm',
30 sourcemap: !!isDevelopmentBuild,
31 ...(isDevelopmentBuild && {
32 dir: 'lib',
33 entryFileNames: '[name].mjs',
34 preserveModules: true,
35 preserveModulesRoot: 'src'
36 }),
37 ...(!isDevelopmentBuild && {
38 file: 'lib/index.mjs',
39 plugins: [terser({ maxWorkers: 2 })]
40 })
41 }
42 ],
43 external: [
44 'node:async_hooks',
45 'node:cluster',
46 'node:crypto',
47 'node:events',
48 'node:os',
49 'node:worker_threads'
50 ],
51 plugins: [
52 typescript({
53 tsconfig: isDevelopmentBuild
54 ? 'tsconfig.development.json'
55 : 'tsconfig.production.json'
56 }),
57 del({
58 targets: ['lib/*']
59 }),
60 isAnalyzeBuild && analyze(),
61 isDocumentationBuild && command('pnpm typedoc')
62 ]
63 }