-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesbuild.config.js
38 lines (35 loc) · 899 Bytes
/
esbuild.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
const pkg = require('./package.json');
const esbuild = require('esbuild');
config = [
{
outfile: pkg.main,
format: 'cjs',
},
{
outfile: pkg.module,
format: 'esm'
}
]
const watchChange = process.argv.slice(2).includes('--watch');
function build (watchChange) {
config.forEach(c => {
esbuild.build({
entryPoints: ['./src/index.ts'],
bundle: true,
minify: true,
platform: 'node',
sourcemap: true,
target: 'es6',
...c,
watch: watchChange,
}).then((r) => {
if (!watchChange) return;
console.clear();
console.log('\x1b[32m%s\x1b[0m', 'esbuild watch start');
}).catch((e) => {
console.error('esbuild error', e);
process.exit(1);
});
});
}
build(watchChange);