generated from sonofmagic/npm-lib-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.ts
81 lines (78 loc) · 1.99 KB
/
rollup.config.ts
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
import typescript from '@rollup/plugin-typescript'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import { visualizer } from 'rollup-plugin-visualizer'
import { RollupOptions } from 'rollup'
import json from '@rollup/plugin-json'
import { readFileSync } from 'node:fs'
const pkg = JSON.parse(
readFileSync('./package.json', {
encoding: 'utf8'
})
)
// import replace from '@rollup/plugin-replace'
// import terser from '@rollup/plugin-terser'
const isProd = process.env.NODE_ENV === 'production'
const isDev = process.env.NODE_ENV === 'development'
const dependencies = pkg.dependencies as Record<string, string> | undefined
const config: RollupOptions = {
input: 'src/index.ts',
// { index: 'src/index.ts', cli: 'src/cli.ts' },
output: [
{
file: pkg.main,
format: 'cjs',
sourcemap: isDev,
exports: 'auto',
plugins: [
isProd
? visualizer({
filename: 'stats/cjs.html'
})
: undefined
],
esModule: true,
generatedCode: {
reservedNamesAsProps: false
},
interop: 'compat',
systemNullSetters: false
},
{
format: 'esm',
file: pkg.module,
sourcemap: isDev,
plugins: [
isProd
? visualizer({
filename: 'stats/esm.html'
})
: undefined
],
esModule: true,
generatedCode: {
reservedNamesAsProps: false
},
interop: 'compat',
systemNullSetters: false
}
// {
// dir: 'dist',
// format: 'cjs',
// sourcemap: isDev,
// exports: 'auto'
// },
],
makeAbsoluteExternalsRelative: true,
preserveEntrySignatures: 'strict',
plugins: [
json(),
nodeResolve({
preferBuiltins: true
}),
commonjs(),
typescript({ tsconfig: './tsconfig.build.json', sourceMap: isDev })
],
external: [...(dependencies ? Object.keys(dependencies) : [])]
}
export default config