-
Notifications
You must be signed in to change notification settings - Fork 0
/
esbuild.config.js
51 lines (47 loc) · 1.15 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const esbuild = require('esbuild')
const path = require('path')
let mode = (process.env.RAILS_ENV === "production" ? "production" : "build")
process.argv.slice(2).forEach((arg) => {
if (arg === '--watch') {
mode = 'watch'
} else if (arg === '--production') {
mode = 'production'
} else if(arg === '--test') {
mode = 'test';
}
})
let opts = {
entryPoints: [
'app/javascript/packs/application.js',
],
bundle: true,
sourcemap: true,
logLevel: 'info',
target: 'es2016',
outdir: path.join(process.cwd(), "app/assets/builds"),
plugins: [],
loader: { '.js': 'jsx' }
}
if (mode === 'watch') {
opts = {
watch: true,
sourcemap: 'inline',
...opts
}
}
if (mode === 'production') {
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)
})