-
Notifications
You must be signed in to change notification settings - Fork 0
/
esbuild.js
57 lines (52 loc) · 1.11 KB
/
esbuild.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
import esbuild from 'esbuild';
import { emptyDir } from 'fs-extra';
import path from 'node:path';
import glob from 'fast-glob';
const entries = glob.sync(['src/**', '!**/*.d.ts']);
const configs = [
{
entryPoints: entries,
bundle: false,
packages: 'external',
outdir: 'dist/es',
minify: false,
sourcemap: false,
treeShaking: false,
splitting: false,
target: 'es6',
format: 'esm',
tsconfig: './tsconfig.build.json',
},
{
entryPoints: entries,
bundle: false,
outdir: 'dist/lib',
minify: false,
sourcemap: false,
splitting: false,
treeShaking: false,
target: 'es6',
format: 'cjs',
tsconfig: './tsconfig.build.json',
},
];
async function build() {
// 清理输出目录
await emptyDir(path.resolve('./dist'));
// 构建所有配置
for (let config of configs) {
try {
await esbuild.build(config);
} catch (error) {
console.error(
`Build failed for config: ${JSON.stringify(config)}`,
error,
);
process.exit(1);
}
}
}
build().catch(err => {
console.error(err);
process.exit(1);
});