forked from nkohari/apocrypha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
37 lines (33 loc) · 860 Bytes
/
build.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
#!/usr/bin/env node
const {build, buildSync} = require('esbuild');
const commandLineArgs = require('command-line-args');
const args = commandLineArgs([{name: 'watch', alias: 'w', type: Boolean}]);
const options = {
bundle: true,
entryPoints: ['src/index.ts'],
external: ['chokidar', 'fsevents'],
format: 'esm',
outdir: 'dist',
platform: 'node',
sourcemap: 'external',
};
if (args.watch) {
build({
...options,
format: 'cjs',
watch: {
onRebuild(error, result) {
if (error) {
console.error('esbuild error: %s', error);
} else {
console.log('esbuild ran successfully');
}
},
},
}).then(() => {
console.log('esbuild complete, watching for changes');
});
} else {
buildSync({...options, format: 'cjs'});
buildSync({...options, outExtension: {'.js': '.mjs'}});
}