1 import * as os from 'node:os'
2 import { env } from 'node:process'
3 import { dts } from 'rollup-plugin-dts'
4 import terser from '@rollup/plugin-terser'
5 import typescript from '@rollup/plugin-typescript'
6 import analyze from 'rollup-plugin-analyzer'
7 import command from 'rollup-plugin-command'
8 import del from 'rollup-plugin-delete'
9 import { defineConfig } from 'rollup'
11 const availableParallelism = () => {
12 let availableParallelism = 1
14 availableParallelism = os.availableParallelism()
16 const cpus = os.cpus()
17 if (Array.isArray(cpus) && cpus.length > 0) {
18 availableParallelism = cpus.length
21 return availableParallelism
24 const isDevelopmentBuild = env.BUILD === 'development'
25 const isAnalyzeBuild = env.ANALYZE
26 const isDocumentationBuild = env.DOCUMENTATION
27 const sourcemap = env.SOURCEMAP !== 'false'
29 const maxWorkers = Math.floor(availableParallelism() / 2)
31 export default defineConfig([
33 input: './src/index.ts',
34 strictDeprecations: true,
38 ...(isDevelopmentBuild && {
40 entryFileNames: '[name].cjs',
41 chunkFileNames: '[name]-[hash].cjs',
42 preserveModules: true,
43 preserveModulesRoot: './src'
45 ...(!isDevelopmentBuild && {
46 file: './lib/index.cjs',
47 plugins: [terser({ maxWorkers })]
55 ...(isDevelopmentBuild && {
57 entryFileNames: '[name].mjs',
58 chunkFileNames: '[name]-[hash].mjs',
59 preserveModules: true,
60 preserveModulesRoot: './src'
62 ...(!isDevelopmentBuild && {
63 file: './lib/index.mjs',
64 plugins: [terser({ maxWorkers })]
71 external: [/^node:*/],
74 tsconfig: './tsconfig.build.json',
82 Boolean(isAnalyzeBuild) && analyze(),
83 Boolean(isDocumentationBuild) && command('pnpm typedoc')
87 input: './lib/dts/index.d.ts',
88 output: [{ format: 'esm', file: './lib/index.d.ts' }],
89 external: [/^node:*/],
93 targets: ['./lib/dts'],
96 Boolean(isAnalyzeBuild) && analyze()