build: cleanup bundler configuration
[poolifier.git] / rollup.config.mjs
CommitLineData
8424fb0d 1import { cpus } from 'node:os'
8f98d75d
JB
2import terser from '@rollup/plugin-terser'
3import typescript from '@rollup/plugin-typescript'
f45e4999 4import analyze from 'rollup-plugin-analyzer'
5ea22628 5import command from 'rollup-plugin-command'
eae1fc25 6import del from 'rollup-plugin-delete'
660940b0
JB
7
8const isDevelopmentBuild = process.env.BUILD === 'development'
9dc351aa
JB
9const isAnalyzeBuild = process.env.ANALYZE
10const isDocumentationBuild = process.env.DOCUMENTATION
660940b0 11
8424fb0d 12const maxWorkers = cpus().length / 2
509e904b 13
660940b0
JB
14export default {
15 input: 'src/index.ts',
f1dbb029 16 strictDeprecations: true,
34a0cfab
JB
17 output: [
18 {
34a0cfab
JB
19 format: 'cjs',
20 sourcemap: !!isDevelopmentBuild,
21 ...(isDevelopmentBuild && {
5119cf1a 22 dir: 'lib',
34a0cfab
JB
23 preserveModules: true,
24 preserveModulesRoot: 'src'
25 }),
5119cf1a
JB
26 ...(!isDevelopmentBuild && {
27 file: 'lib/index.js',
509e904b 28 plugins: [terser({ maxWorkers })]
5119cf1a 29 })
34a0cfab
JB
30 },
31 {
34a0cfab
JB
32 format: 'esm',
33 sourcemap: !!isDevelopmentBuild,
34a0cfab 34 ...(isDevelopmentBuild && {
5119cf1a 35 dir: 'lib',
34a0cfab
JB
36 entryFileNames: '[name].mjs',
37 preserveModules: true,
38 preserveModulesRoot: 'src'
39 }),
5119cf1a
JB
40 ...(!isDevelopmentBuild && {
41 file: 'lib/index.mjs',
509e904b 42 plugins: [terser({ maxWorkers })]
5119cf1a 43 })
34a0cfab
JB
44 }
45 ],
fc3e6586
JB
46 external: [
47 'node:async_hooks',
48 'node:cluster',
49 'node:crypto',
50 'node:events',
51 'node:os',
52 'node:worker_threads'
53 ],
660940b0 54 plugins: [
8f98d75d 55 typescript({
660940b0
JB
56 tsconfig: isDevelopmentBuild
57 ? 'tsconfig.development.json'
ce68dd22 58 : 'tsconfig.production.json'
660940b0
JB
59 }),
60 del({
f4162974 61 targets: ['lib/*']
f45e4999 62 }),
9dc351aa
JB
63 isAnalyzeBuild && analyze(),
64 isDocumentationBuild && command('pnpm typedoc')
660940b0
JB
65 ]
66}