chore: generate documentation
[poolifier.git] / rollup.config.mjs
... / ...
CommitLineData
1import { cpus } from 'node:os'
2import terser from '@rollup/plugin-terser'
3import typescript from '@rollup/plugin-typescript'
4import analyze from 'rollup-plugin-analyzer'
5import command from 'rollup-plugin-command'
6import del from 'rollup-plugin-delete'
7
8const isDevelopmentBuild = process.env.BUILD === 'development'
9const isAnalyzeBuild = process.env.ANALYZE
10const isDocumentationBuild = process.env.DOCUMENTATION
11
12const maxWorkers = cpus().length / 2
13
14export default {
15 input: 'src/index.ts',
16 strictDeprecations: true,
17 output: [
18 {
19 format: 'cjs',
20 ...(isDevelopmentBuild && {
21 dir: 'lib',
22 sourcemap: true,
23 preserveModules: true,
24 preserveModulesRoot: 'src'
25 }),
26 ...(!isDevelopmentBuild && {
27 file: 'lib/index.js',
28 plugins: [terser({ maxWorkers })]
29 })
30 },
31 {
32 format: 'esm',
33 ...(isDevelopmentBuild && {
34 dir: 'lib',
35 sourcemap: true,
36 entryFileNames: '[name].mjs',
37 preserveModules: true,
38 preserveModulesRoot: 'src'
39 }),
40 ...(!isDevelopmentBuild && {
41 file: 'lib/index.mjs',
42 plugins: [terser({ maxWorkers })]
43 })
44 }
45 ],
46 external: [
47 'node:async_hooks',
48 'node:cluster',
49 'node:crypto',
50 'node:events',
51 'node:os',
52 'node:perf_hooks',
53 'node:worker_threads'
54 ],
55 plugins: [
56 typescript({
57 tsconfig: isDevelopmentBuild
58 ? 'tsconfig.development.json'
59 : 'tsconfig.production.json'
60 }),
61 del({
62 targets: ['lib/*']
63 }),
64 isAnalyzeBuild && analyze(),
65 isDocumentationBuild && command('pnpm typedoc')
66 ]
67}