-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathrollup.config.js
62 lines (56 loc) · 1.34 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
import { transformSync } from 'esbuild';
import { defineConfig } from 'rollup';
import esbuildPlugin from 'rollup-plugin-esbuild';
export default defineConfig([
// dev
define({ dev: true }),
// prod
define({ dev: false }),
]);
/** @returns {import('rollup').RollupOptions} */
function define({ dev = false }) {
const alias = dev ? 'dev' : 'prod',
shouldMangle = !dev;
/** @type {Record<string, string | false>} */
let mangleCache = {};
return {
input: {
[alias]: 'src/index.ts',
},
treeshake: true,
maxParallelFileOps: shouldMangle ? 1 : 20,
output: {
format: 'esm',
dir: 'dist',
chunkFileNames: `${alias}/[name].js`,
},
plugins: [
esbuildPlugin({
target: 'esnext',
platform: 'neutral',
tsconfig: 'tsconfig.build.json',
minify: false,
define: {
__DEV__: dev ? 'true' : 'false',
},
}),
shouldMangle && {
name: 'mangle',
transform(code) {
const result = transformSync(code, {
target: 'esnext',
minify: false,
mangleProps: /^_/,
mangleCache,
loader: 'ts',
});
mangleCache = {
...mangleCache,
...result.mangleCache,
};
return result.code;
},
},
],
};
}