1 import * as os from 'node:os'
2 import { env } from 'node:process'
4 import terser from '@rollup/plugin-terser'
5 import typescript from '@rollup/plugin-typescript'
6 import { defineConfig } from 'rollup'
7 import analyze from 'rollup-plugin-analyzer'
8 import command from 'rollup-plugin-command'
9 import del from 'rollup-plugin-delete'
10 import { dts } from 'rollup-plugin-dts'
12 const availableParallelism = () => {
13 let availableParallelism = 1
15 // eslint-disable-next-line n/no-unsupported-features/node-builtins
16 availableParallelism = os.availableParallelism()
18 const cpus = os.cpus()
19 if (Array.isArray(cpus) && cpus.length > 0) {
20 availableParallelism = cpus.length
23 return availableParallelism
26 const isDevelopmentBuild = env.BUILD === 'development'
27 const isAnalyzeBuild = Boolean(env.ANALYZE)
28 const isDocumentationBuild = Boolean(env.DOCUMENTATION)
29 const sourcemap = env.SOURCEMAP !== 'false'
31 const maxWorkers = Math.floor(availableParallelism() / 2)
33 export default defineConfig([
35 input: './src/index.ts',
36 strictDeprecations: true,
40 ...(isDevelopmentBuild
43 entryFileNames: '[name].cjs',
44 chunkFileNames: '[name]-[hash].cjs',
45 preserveModules: true,
46 preserveModulesRoot: './src'
49 file: './lib/index.cjs',
50 plugins: [terser({ maxWorkers })]
58 ...(isDevelopmentBuild
61 entryFileNames: '[name].mjs',
62 chunkFileNames: '[name]-[hash].mjs',
63 preserveModules: true,
64 preserveModulesRoot: './src'
67 file: './lib/index.mjs',
68 plugins: [terser({ maxWorkers })]
75 external: [/^node:*/],
78 tsconfig: './tsconfig.build.json',
86 isAnalyzeBuild && analyze(),
87 isDocumentationBuild && command('pnpm typedoc')
91 input: './lib/dts/index.d.ts',
92 strictDeprecations: true,
93 output: [{ format: 'esm', file: './lib/index.d.ts' }],
94 external: [/^node:*/],
98 targets: ['./lib/dts'],
101 isAnalyzeBuild && analyze()