1 import * as os 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'
8 const availableParallelism = () => {
9 let availableParallelism = 1
11 availableParallelism = os.availableParallelism()
13 const numberOfCpus = os.cpus()
14 if (Array.isArray(numberOfCpus) && numberOfCpus.length > 0) {
15 availableParallelism = numberOfCpus.length
18 return availableParallelism
21 const isDevelopmentBuild = process.env.BUILD === 'development'
22 const isAnalyzeBuild = process.env.ANALYZE
23 const isDocumentationBuild = process.env.DOCUMENTATION
25 const maxWorkers = Math.floor(availableParallelism() / 2)
28 input: 'src/index.ts',
29 strictDeprecations: true,
33 ...(isDevelopmentBuild && {
36 preserveModules: true,
37 preserveModulesRoot: 'src'
39 ...(!isDevelopmentBuild && {
41 plugins: [terser({ maxWorkers })]
46 ...(isDevelopmentBuild && {
49 entryFileNames: '[name].mjs',
50 preserveModules: true,
51 preserveModulesRoot: 'src'
53 ...(!isDevelopmentBuild && {
54 file: 'lib/index.mjs',
55 plugins: [terser({ maxWorkers })]
71 tsconfig: isDevelopmentBuild
72 ? 'tsconfig.development.json'
73 : 'tsconfig.production.json'
78 isAnalyzeBuild && analyze(),
79 isDocumentationBuild && command('pnpm typedoc')