-
Notifications
You must be signed in to change notification settings - Fork 0
/
esbuild.js
48 lines (43 loc) · 969 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
import { build, context } from 'esbuild'
/*
TODO: replace mkdir/cp commands from package.json build script
import { promisify } from 'node:util'
import c from 'copy'
const copy = promisify(c)
await copy('./static', 'dist', {
srcBase: 'src'
})
*/
/**
* @type {import('esbuild').BuildOptions}
*/
const config = {
entryPoints: ['./src/index.jsx'],
outfile: './dist/index.js',
sourcemap: 'linked',
minify: true,
bundle: true,
define: {
'process.env.NODE_DEBUG': 'false',
global: 'globalThis'
},
loader: {
'.png': 'file',
'.jpg': 'file',
'.gif': 'file',
'.pdf': 'file',
'.svg': 'file',
'.woff': 'file',
'.woff2': 'file'
}
}
if (process.argv[2] === 'serve') {
const result = await context(config)
const serveResult = await result.serve({
servedir: './dist'
})
console.info(`Server listening on http://127.0.0.1:${serveResult.port}`)
} else {
await build(config)
.catch(() => process.exit(1))
}