refactor: factor out worker message handlers
[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 19 format: 'cjs',
34a0cfab 20 ...(isDevelopmentBuild && {
5119cf1a 21 dir: 'lib',
aef30681 22 sourcemap: true,
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 32 format: 'esm',
34a0cfab 33 ...(isDevelopmentBuild && {
5119cf1a 34 dir: 'lib',
aef30681 35 sourcemap: true,
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',
62c15a68 52 'node:perf_hooks',
fc3e6586
JB
53 'node:worker_threads'
54 ],
660940b0 55 plugins: [
8f98d75d 56 typescript({
660940b0
JB
57 tsconfig: isDevelopmentBuild
58 ? 'tsconfig.development.json'
ce68dd22 59 : 'tsconfig.production.json'
660940b0
JB
60 }),
61 del({
f4162974 62 targets: ['lib/*']
f45e4999 63 }),
9dc351aa
JB
64 isAnalyzeBuild && analyze(),
65 isDocumentationBuild && command('pnpm typedoc')
660940b0
JB
66 ]
67}