-
Notifications
You must be signed in to change notification settings - Fork 1
/
esBuild.js
47 lines (43 loc) · 1.1 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
import { build } from 'esbuild';
const buildConfig = {
bundle: true,
platform: 'browser',
target: 'es2015',
plugins: [
{
name: 'external',
setup(build) {
let filter = /^[^./]|^\.[^./]|^\.\.[^/]/;
build.onResolve({ filter }, (args) => ({
external: true,
path: args.path,
}));
},
},
],
tsconfig: './tsconfig.json',
splitting: true,
entryPoints: ['src/index.ts'],
drop: process.env.NODE_ENV !== 'development' ? ['console', 'debugger'] : [],
watch: process.env.NODE_ENV === 'development',
sourcemap: true,
minify: false,
};
const buildESM = build({
...buildConfig,
format: 'esm',
outdir: 'dist/esm',
outExtension: { '.js': '.mjs' },
splitting: true,
});
const buildCJS = build({
...buildConfig,
outdir: 'dist/cjs',
outExtension: { '.js': '.cjs' },
splitting: false,
});
Promise.all([buildESM, buildCJS])
.then(() => {
console.log('Build success...');
})
.catch(() => process.exit(1));