Commit | Line | Data |
---|---|---|
d5fdc57b | 1 | import * as os from 'node:os' |
b40c4b06 | 2 | import { dts } from 'rollup-plugin-dts' |
8f98d75d JB |
3 | import terser from '@rollup/plugin-terser' |
4 | import typescript from '@rollup/plugin-typescript' | |
f45e4999 | 5 | import analyze from 'rollup-plugin-analyzer' |
5ea22628 | 6 | import command from 'rollup-plugin-command' |
eae1fc25 | 7 | import del from 'rollup-plugin-delete' |
660940b0 | 8 | |
d5fdc57b JB |
9 | const availableParallelism = () => { |
10 | let availableParallelism = 1 | |
11 | try { | |
12 | availableParallelism = os.availableParallelism() | |
13 | } catch { | |
562a4037 JB |
14 | const cpus = os.cpus() |
15 | if (Array.isArray(cpus) && cpus.length > 0) { | |
16 | availableParallelism = cpus.length | |
d5fdc57b JB |
17 | } |
18 | } | |
19 | return availableParallelism | |
20 | } | |
21 | ||
660940b0 | 22 | const isDevelopmentBuild = process.env.BUILD === 'development' |
9dc351aa JB |
23 | const isAnalyzeBuild = process.env.ANALYZE |
24 | const isDocumentationBuild = process.env.DOCUMENTATION | |
660940b0 | 25 | |
d5fdc57b | 26 | const maxWorkers = Math.floor(availableParallelism() / 2) |
509e904b | 27 | |
b40c4b06 JB |
28 | export default [ |
29 | { | |
78cdf6bc | 30 | input: './src/index.ts', |
b40c4b06 JB |
31 | strictDeprecations: true, |
32 | output: [ | |
33 | { | |
34 | format: 'cjs', | |
35 | ...(isDevelopmentBuild && { | |
78cdf6bc | 36 | dir: './lib', |
b40c4b06 JB |
37 | sourcemap: true, |
38 | preserveModules: true, | |
78cdf6bc | 39 | preserveModulesRoot: './src' |
b40c4b06 JB |
40 | }), |
41 | ...(!isDevelopmentBuild && { | |
78cdf6bc | 42 | file: './lib/index.js', |
b40c4b06 JB |
43 | plugins: [terser({ maxWorkers })] |
44 | }) | |
45 | }, | |
46 | { | |
47 | format: 'esm', | |
48 | ...(isDevelopmentBuild && { | |
78cdf6bc | 49 | dir: './lib', |
b40c4b06 JB |
50 | sourcemap: true, |
51 | entryFileNames: '[name].mjs', | |
52 | preserveModules: true, | |
78cdf6bc | 53 | preserveModulesRoot: './src' |
b40c4b06 JB |
54 | }), |
55 | ...(!isDevelopmentBuild && { | |
78cdf6bc | 56 | file: './lib/index.mjs', |
b40c4b06 JB |
57 | plugins: [terser({ maxWorkers })] |
58 | }) | |
59 | } | |
60 | ], | |
61 | external: [ | |
62 | 'node:async_hooks', | |
63 | 'node:cluster', | |
64 | 'node:crypto', | |
65 | 'node:events', | |
66 | 'node:fs', | |
67 | 'node:os', | |
68 | 'node:perf_hooks', | |
69 | 'node:worker_threads' | |
70 | ], | |
71 | plugins: [ | |
72 | typescript({ | |
73 | tsconfig: isDevelopmentBuild | |
2bdcd112 JB |
74 | ? './tsconfig.development.json' |
75 | : './tsconfig.production.json' | |
34a0cfab | 76 | }), |
b40c4b06 | 77 | del({ |
78cdf6bc | 78 | targets: ['./lib/*'] |
34a0cfab | 79 | }), |
b40c4b06 JB |
80 | isAnalyzeBuild && analyze(), |
81 | isDocumentationBuild && command('pnpm typedoc') | |
82 | ] | |
83 | }, | |
84 | { | |
85 | input: './lib/dts/index.d.ts', | |
78cdf6bc | 86 | output: [{ format: 'esm', file: './lib/index.d.ts' }], |
b40c4b06 JB |
87 | external: [ |
88 | 'node:async_hooks', | |
89 | 'node:cluster', | |
90 | 'node:events', | |
91 | 'node:perf_hooks', | |
92 | 'node:worker_threads' | |
93 | ], | |
94 | plugins: [ | |
95 | dts(), | |
96 | del({ | |
78cdf6bc | 97 | targets: ['./lib/dts'], |
b40c4b06 | 98 | hook: 'buildEnd' |
096c02a7 JB |
99 | }), |
100 | isAnalyzeBuild && analyze() | |
b40c4b06 JB |
101 | ] |
102 | } | |
103 | ] |