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 availableParallelism = os.availableParallelism()
17 const cpus = os.cpus()
18 if (Array.isArray(cpus) && cpus.length > 0) {
19 availableParallelism = cpus.length
22 return availableParallelism
25 const isDevelopmentBuild = env.BUILD === 'development'
26 const isAnalyzeBuild = Boolean(env.ANALYZE)
27 const isDocumentationBuild = Boolean(env.DOCUMENTATION)
28 const sourcemap = env.SOURCEMAP !== 'false'
30 const maxWorkers = Math.floor(availableParallelism() / 2)
32 export default defineConfig([
34 input: './src/index.ts',
35 strictDeprecations: true,
39 ...(isDevelopmentBuild
42 entryFileNames: '[name].cjs',
43 chunkFileNames: '[name]-[hash].cjs',
44 preserveModules: true,
45 preserveModulesRoot: './src'
48 file: './lib/index.cjs',
49 plugins: [terser({ maxWorkers })]
57 ...(isDevelopmentBuild
60 entryFileNames: '[name].mjs',
61 chunkFileNames: '[name]-[hash].mjs',
62 preserveModules: true,
63 preserveModulesRoot: './src'
66 file: './lib/index.mjs',
67 plugins: [terser({ maxWorkers })]
74 external: [/^node:*/],
77 tsconfig: './tsconfig.build.json',
85 isAnalyzeBuild && analyze(),
86 isDocumentationBuild && command('pnpm typedoc')
90 input: './lib/dts/index.d.ts',
91 strictDeprecations: true,
92 output: [{ format: 'esm', file: './lib/index.d.ts' }],
93 external: [/^node:*/],
97 targets: ['./lib/dts'],
100 isAnalyzeBuild && analyze()