-
Notifications
You must be signed in to change notification settings - Fork 1
/
esbuild.js
54 lines (46 loc) · 987 Bytes
/
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
/* globals process */
import esbuild from 'esbuild';
import { sassPlugin } from 'esbuild-sass-plugin';
// Decide which mode to proceed with
let mode = 'build';
const sass = sassPlugin();
process.argv.slice(2).forEach((arg) => {
if (arg === '--watch') {
mode = 'watch';
} else if (arg === '--deploy') {
mode = 'deploy';
}
});
const opts = {
entryPoints: ['src/index.ts'],
outdir: 'dist',
bundle: true,
sourcemap: true,
splitting: true,
watch: false,
minify: false,
format: 'esm',
target: ['esnext'],
plugins: [sass],
};
if (mode === 'watch') {
opts.entryPoints = ['playground/js/app.ts'];
opts.outdir = 'playground/priv/static';
opts.watch = true;
}
if (mode === 'deploy') {
opts.minify = true;
}
esbuild
.build(opts)
.then((result) => {
if (mode === 'watch') {
process.stdin.pipe(process.stdout);
process.stdin.on('end', () => {
result.stop();
});
}
})
.catch(() => {
process.exit(1);
});