-
Notifications
You must be signed in to change notification settings - Fork 2
/
esbuild-script.js
61 lines (53 loc) · 1.47 KB
/
esbuild-script.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
52
53
54
55
56
57
58
59
60
61
const esbuild = require('esbuild');
const copyStaticFiles = require('esbuild-copy-static-files');
const config = {
entryPoints: ['./src/index.web.ts'],
outdir: './build',
bundle: true,
define: {},
loader: {
'.wgsl': 'text',
},
// plugins
plugins: [
copyStaticFiles({
src: './static',
dest: './build',
dereference: true,
errorOnExist: false,
recursive: true,
}),
],
};
const defineProductionFlag = (flag) =>
(config.define.IS_PRODUCTION = String(flag));
async function buildProd() {
console.log('Executing prod build');
defineProductionFlag(true);
config.minify = true;
// config.format = 'esm'; // produces invalid build? some module imports or smth. 'type="module"' in <script>?
config.sourcemap = true;
config.target = 'chrome100,firefox100,safari15'.split(',');
await esbuild.build(config);
console.log(
`Build finished sucesfully. The files are in '${config.outdir}' directory.`
);
}
async function startDev() {
console.log('Starting dev compile process');
defineProductionFlag(false);
console.log(`Using entry points:`, config.entryPoints);
const ctx = await esbuild.context(config);
await ctx.watch();
console.log(`Done. Watching for code changes...`);
// let { host, port } = await ctx.serve({
// servedir: 'build',
// });
// console.log(`Serve: http://localhost:${port}/`);
}
const isDev = process.argv.some((e) => e == '--dev');
if (isDev) {
startDev();
} else {
buildProd();
}