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