-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbuild.mjs
47 lines (39 loc) · 973 Bytes
/
build.mjs
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
import * as esbuild from 'esbuild';
import htmlPlugin from '@chialab/esbuild-plugin-html';
const isDev = process.argv.includes('--dev');
const esbuildOptions = {
entryPoints: ['src/index.html'],
minify: true,
bundle: false,
sourcemap: false,
chunkNames: 'static/[name]-[hash]',
plugins: [
htmlPlugin({
minifyOptions: {
minifySvg: false,
},
}),
],
outdir: 'public/',
define: {
"process.env.NODE_ENV": JSON.stringify("production"),
},
};
if (isDev) {
esbuildOptions.banner = {
js: `window.DEV_MODE = true;new EventSource("/esbuild").addEventListener("change", () => location.reload());`
};
}
const context = await esbuild.context(esbuildOptions);
if (isDev) {
await context.watch();
const { host, port } = await context.serve({
host: 'localhost',
servedir: 'public/',
});
console.log(`Serving at http://${host}:${port}`);
} else {
console.log('Building');
await context.rebuild();
await context.dispose();
}