build(deps-dev): apply updates
[poolifier.git] / rollup.config.mjs
CommitLineData
d5fdc57b 1import * as os 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 7
d5fdc57b
JB
8const availableParallelism = () => {
9 let availableParallelism = 1
10 try {
11 availableParallelism = os.availableParallelism()
12 } catch {
13 const numberOfCpus = os.cpus()
14 if (Array.isArray(numberOfCpus) && numberOfCpus.length > 0) {
15 availableParallelism = numberOfCpus.length
16 }
17 }
18 return availableParallelism
19}
20
660940b0 21const isDevelopmentBuild = process.env.BUILD === 'development'
9dc351aa
JB
22const isAnalyzeBuild = process.env.ANALYZE
23const isDocumentationBuild = process.env.DOCUMENTATION
660940b0 24
d5fdc57b 25const maxWorkers = Math.floor(availableParallelism() / 2)
509e904b 26
660940b0
JB
27export default {
28 input: 'src/index.ts',
f1dbb029 29 strictDeprecations: true,
34a0cfab
JB
30 output: [
31 {
34a0cfab 32 format: 'cjs',
34a0cfab 33 ...(isDevelopmentBuild && {
5119cf1a 34 dir: 'lib',
aef30681 35 sourcemap: true,
34a0cfab
JB
36 preserveModules: true,
37 preserveModulesRoot: 'src'
38 }),
5119cf1a
JB
39 ...(!isDevelopmentBuild && {
40 file: 'lib/index.js',
509e904b 41 plugins: [terser({ maxWorkers })]
5119cf1a 42 })
34a0cfab
JB
43 },
44 {
34a0cfab 45 format: 'esm',
34a0cfab 46 ...(isDevelopmentBuild && {
5119cf1a 47 dir: 'lib',
aef30681 48 sourcemap: true,
34a0cfab
JB
49 entryFileNames: '[name].mjs',
50 preserveModules: true,
51 preserveModulesRoot: 'src'
52 }),
5119cf1a
JB
53 ...(!isDevelopmentBuild && {
54 file: 'lib/index.mjs',
509e904b 55 plugins: [terser({ maxWorkers })]
5119cf1a 56 })
34a0cfab
JB
57 }
58 ],
fc3e6586
JB
59 external: [
60 'node:async_hooks',
61 'node:cluster',
62 'node:crypto',
63 'node:events',
3d6dd312 64 'node:fs',
fc3e6586 65 'node:os',
62c15a68 66 'node:perf_hooks',
fc3e6586
JB
67 'node:worker_threads'
68 ],
660940b0 69 plugins: [
8f98d75d 70 typescript({
660940b0
JB
71 tsconfig: isDevelopmentBuild
72 ? 'tsconfig.development.json'
ce68dd22 73 : 'tsconfig.production.json'
660940b0
JB
74 }),
75 del({
f4162974 76 targets: ['lib/*']
f45e4999 77 }),
9dc351aa
JB
78 isAnalyzeBuild && analyze(),
79 isDocumentationBuild && command('pnpm typedoc')
660940b0
JB
80 ]
81}