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'
8 import { defineConfig } from 'rollup'
10 const availableParallelism = () => {
11 let availableParallelism = 1
13 availableParallelism = os.availableParallelism()
15 const cpus = os.cpus()
16 if (Array.isArray(cpus) && cpus.length > 0) {
17 availableParallelism = cpus.length
20 return availableParallelism
23 const isDevelopmentBuild = process.env.BUILD === 'development'
24 const isAnalyzeBuild = process.env.ANALYZE
25 const isDocumentationBuild = process.env.DOCUMENTATION
27 const maxWorkers = Math.floor(availableParallelism() / 2)
29 export default defineConfig([
31 input: './src/index.ts',
32 strictDeprecations: true,
36 ...(isDevelopmentBuild && {
39 preserveModules: true,
40 preserveModulesRoot: './src'
42 ...(!isDevelopmentBuild && {
43 file: './lib/index.js',
45 plugins: [terser({ maxWorkers })]
50 ...(isDevelopmentBuild && {
53 entryFileNames: '[name].mjs',
54 chunkFileNames: '[name]-[hash].mjs',
55 preserveModules: true,
56 preserveModulesRoot: './src'
58 ...(!isDevelopmentBuild && {
59 file: './lib/index.mjs',
61 plugins: [terser({ maxWorkers })]
77 tsconfig: './tsconfig.build.json'
82 isAnalyzeBuild && analyze(),
83 isDocumentationBuild && command('pnpm typedoc')
87 input: './lib/dts/index.d.ts',
88 output: [{ format: 'esm', file: './lib/index.d.ts' }],
99 targets: ['./lib/dts'],
102 isAnalyzeBuild && analyze()