-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathesbuild.js
44 lines (41 loc) · 911 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
const esbuild = require('esbuild')
// Decide which mode to proceed with
let mode = 'build'
process.argv.slice(2).forEach((arg) => {
if (arg === '--watch') {
mode = 'watch'
} else if (arg === '--release') {
mode = 'release'
}
})
// Define esbuild options + extras for watch and deploy
let opts = {
entryPoints: ['js/app.js'],
bundle: true,
logLevel: 'info',
target: 'es2016',
outdir: '../dist/js',
}
if (mode === 'watch') {
opts = {
watch: true,
sourcemap: 'inline',
...opts
}
}
if (mode === 'release') {
opts = {
minify: true,
...opts
}
}
// Start esbuild with previously defined options
// Stop the watcher when STDIN gets closed (no zombies please!)
esbuild.build(opts).then((result) => {
if (mode === 'watch') {
process.stdin.pipe(process.stdout)
process.stdin.on('end', () => { result.stop() })
}
}).catch((error) => {
process.exit(1)
})