-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
100 lines (96 loc) · 2.13 KB
/
rollup.config.js
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
100
import path from 'path'
import { defineConfig } from 'rollup'
import ts from 'rollup-plugin-typescript2'
import replace from '@rollup/plugin-replace'
import { terser } from 'rollup-plugin-terser'
import { version } from './package.json'
const builds = {
'cjs-dev': {
format: 'cjs',
env: 'development',
},
'cjs-prod': {
format: 'cjs',
env: 'production',
},
'esm-dev': {
format: 'esm',
env: 'development',
},
'esm-prod': {
format: 'esm',
env: 'production',
},
'umd-dev': {
format: 'umd',
env: 'development',
},
'umd-prod': {
format: 'umd',
env: 'production',
},
}
function createConfig(name) {
const { format, env } = builds[name]
const isProd = env === 'production'
return defineConfig({
input: path.resolve(__dirname, './src/index.ts'),
output: {
file: path.resolve(
__dirname,
`./dist/reactivity.${[format, isProd && 'min']
.filter(Boolean)
.join('.')}.js`,
),
format,
banner:
'/*!\n' +
` * @dupfei/reactivity v${version}\n` +
` * (c) 2022-${new Date().getFullYear()} dupfei\n` +
' * Released under the MIT License.\n' +
' */',
name: 'Reactivity',
exports: 'auto',
},
plugins: [
ts({
tsconfig: './src/tsconfig.json',
include: ['./src/**/*'],
useTsconfigDeclarationDir: true,
tsconfigOverride: {
target: 'es5',
declaration: false,
},
}),
replace({
preventAssignment: true,
values: {
__VERSION__: `"${version}"`,
__DEV__: !isProd,
},
}),
isProd &&
terser({
toplevel: true,
compress: {
ecma: 5,
pure_getters: true,
},
format: {
ascii_only: true,
},
safari10: true,
}),
].filter(Boolean),
})
}
let config
if (process.env.TARGET) {
config = createConfig(process.env.TARGET)
} else {
config = Object.keys(builds).reduce((acc, name) => {
acc.push(createConfig(name))
return acc
}, [])
}
export default config