build(deps-dev): bump @biomejs/biome from 1.6.2 to 1.6.3
[poolifier.git] / rollup.config.mjs
... / ...
CommitLineData
1import * as os from 'node:os'
2import { env } from 'node:process'
3
4import terser from '@rollup/plugin-terser'
5import typescript from '@rollup/plugin-typescript'
6import { defineConfig } from 'rollup'
7import analyze from 'rollup-plugin-analyzer'
8import command from 'rollup-plugin-command'
9import del from 'rollup-plugin-delete'
10import { dts } from 'rollup-plugin-dts'
11
12const availableParallelism = () => {
13 let availableParallelism = 1
14 try {
15 availableParallelism = os.availableParallelism()
16 } catch {
17 const cpus = os.cpus()
18 if (Array.isArray(cpus) && cpus.length > 0) {
19 availableParallelism = cpus.length
20 }
21 }
22 return availableParallelism
23}
24
25const isDevelopmentBuild = env.BUILD === 'development'
26const isAnalyzeBuild = Boolean(env.ANALYZE)
27const isDocumentationBuild = Boolean(env.DOCUMENTATION)
28const sourcemap = env.SOURCEMAP !== 'false'
29
30const maxWorkers = Math.floor(availableParallelism() / 2)
31
32export default defineConfig([
33 {
34 input: './src/index.ts',
35 strictDeprecations: true,
36 output: [
37 {
38 format: 'cjs',
39 ...(isDevelopmentBuild
40 ? {
41 dir: './lib',
42 entryFileNames: '[name].cjs',
43 chunkFileNames: '[name]-[hash].cjs',
44 preserveModules: true,
45 preserveModulesRoot: './src'
46 }
47 : {
48 file: './lib/index.cjs',
49 plugins: [terser({ maxWorkers })]
50 }),
51 ...(sourcemap && {
52 sourcemap
53 })
54 },
55 {
56 format: 'esm',
57 ...(isDevelopmentBuild
58 ? {
59 dir: './lib',
60 entryFileNames: '[name].mjs',
61 chunkFileNames: '[name]-[hash].mjs',
62 preserveModules: true,
63 preserveModulesRoot: './src'
64 }
65 : {
66 file: './lib/index.mjs',
67 plugins: [terser({ maxWorkers })]
68 }),
69 ...(sourcemap && {
70 sourcemap
71 })
72 }
73 ],
74 external: [/^node:*/],
75 plugins: [
76 typescript({
77 tsconfig: './tsconfig.build.json',
78 compilerOptions: {
79 sourceMap: sourcemap
80 }
81 }),
82 del({
83 targets: ['./lib/*']
84 }),
85 isAnalyzeBuild && analyze(),
86 isDocumentationBuild && command('pnpm typedoc')
87 ]
88 },
89 {
90 input: './lib/dts/index.d.ts',
91 strictDeprecations: true,
92 output: [{ format: 'esm', file: './lib/index.d.ts' }],
93 external: [/^node:*/],
94 plugins: [
95 dts(),
96 del({
97 targets: ['./lib/dts'],
98 hook: 'buildEnd'
99 }),
100 isAnalyzeBuild && analyze()
101 ]
102 }
103])