1 import * as os from 'node:os'
2 import { dts } from 'rollup-plugin-dts'
3 import terser from '@rollup/plugin-terser'
4 import typescript from '@rollup/plugin-typescript'
5 import analyze from 'rollup-plugin-analyzer'
6 import command from 'rollup-plugin-command'
7 import del from 'rollup-plugin-delete'
9 const availableParallelism = () => {
10 let availableParallelism = 1
12 availableParallelism = os.availableParallelism()
14 const cpus = os.cpus()
15 if (Array.isArray(cpus) && cpus.length > 0) {
16 availableParallelism = cpus.length
19 return availableParallelism
22 const isDevelopmentBuild = process.env.BUILD === 'development'
23 const isAnalyzeBuild = process.env.ANALYZE
24 const isDocumentationBuild = process.env.DOCUMENTATION
26 const maxWorkers = Math.floor(availableParallelism() / 2)
30 input: './src/index.ts',
31 strictDeprecations: true,
35 ...(isDevelopmentBuild && {
38 preserveModules: true,
39 preserveModulesRoot: './src'
41 ...(!isDevelopmentBuild && {
42 file: './lib/index.js',
43 plugins: [terser({ maxWorkers })]
48 ...(isDevelopmentBuild && {
51 entryFileNames: '[name].mjs',
52 preserveModules: true,
53 preserveModulesRoot: './src'
55 ...(!isDevelopmentBuild && {
56 file: './lib/index.mjs',
57 plugins: [terser({ maxWorkers })]
73 tsconfig: isDevelopmentBuild
74 ? './tsconfig.development.json'
75 : './tsconfig.production.json'
80 isAnalyzeBuild && analyze(),
81 isDocumentationBuild && command('pnpm typedoc')
85 input: './lib/dts/index.d.ts',
86 output: [{ format: 'esm', file: './lib/index.d.ts' }],
97 targets: ['./lib/dts'],
100 isAnalyzeBuild && analyze()