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