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