forked from nornagon/saxi
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.mjs
52 lines (49 loc) · 1.32 KB
/
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
48
49
50
51
import { context, build } from 'esbuild';
import inlineWorker from 'esbuild-plugin-inline-worker';
import { htmlPlugin as html } from '@craftamap/esbuild-plugin-html';
const buildOptions = {
entryPoints: ['src/ui.tsx'],
bundle: true,
platform: 'browser',
target: 'es2020',
minify: true,
sourcemap: true,
metafile: true,
logLevel: 'debug',
outdir: 'dist/ui',
tsconfig: 'tsconfig.web.json',
loader: { '.svg': 'file' },
define: {
IS_WEB: process.env.IS_WEB ?? '0',
},
plugins: [ inlineWorker(),
html({
files: [{
entryPoints: [ 'src/ui.tsx'],
filename: 'index.html',
htmlTemplate: 'src/index.html',
scriptLoading: 'defer',
}]
})
],
resolveExtensions: ['.js', '.ts', '.tsx', '.svg', '.worker.js'],
};
(async () => {
try {
if (process.env.BUILD_MODE === 'development') {
// enables live-reloading
const ctx = await context({
...buildOptions,
banner: { js: "new EventSource('/esbuild').addEventListener('change', () => location.reload());" }
})
await ctx.watch();
const { host, port } = await ctx.serve({servedir: 'dist/ui', port: 9080 });
console.log(`http://${host}:${port}`)
} else {
await build(buildOptions);
}
} catch (error) {
console.error(error);
process.exit(1);
}
})();