-
Notifications
You must be signed in to change notification settings - Fork 2
/
esbuild.js
45 lines (38 loc) · 1.18 KB
/
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
#!/usr/bin/env node
'use strict'
const esbuild = require('esbuild')
const { join: shJoin } = require('shlex')
const isProduction = process.env.NODE_ENV === 'production'
const options = {
entryPoints: process.argv.slice(2),
bundle: true,
sourcemap: true,
minify: isProduction,
define: {},
outdir: 'app/assets/builds',
}
if (process.env.NODE_ENV) {
options.define['process.env.NODE_ENV'] = JSON.stringify(process.env.NODE_ENV)
} else {
options.define['process.env.NODE_ENV'] = JSON.stringify('development')
}
function optionsToArgs(options) {
const args = ['esbuild']
if (options.bundle) args.push('--bundle')
if (options.sourcemap) args.push('--sourcemap')
if (options.minify) args.push('--minify')
if (options.outdir) args.push(`--outdir=${options.outdir}`)
if (options.define) {
for (const [key, value] of Object.entries(options.define)) {
args.push(`--define:${key}=${value}`)
}
}
if (Array.isArray(options.entryPoints)) {
args.push(...options.entryPoints)
}
return shJoin(args)
}
console.log(`+ ${optionsToArgs(options)}`)
// "info" is the default log level for CLI usage, which we emulate.
options.logLevel = 'info'
esbuild.buildSync(options)