forked from RAEvents/tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.mjs
More file actions
32 lines (26 loc) · 684 Bytes
/
build.mjs
File metadata and controls
32 lines (26 loc) · 684 Bytes
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
import esbuild from "esbuild";
async function build() {
return await esbuild.context({
entryPoints: ["src/app.js", "src/index.html"],
outdir: "build",
bundle: true,
minify: true,
sourcemap: true,
format: "esm",
loader: { ".html": "copy" },
});
}
async function serve(ctx) {
await ctx.watch();
let { host, port } = await ctx.serve({
servedir: "build",
onRequest: r => console.log(`${r.method} ${r.path} ${r.status}`),
});
console.log(`Serving at ${host}:${port}`);
}
const ctx = await build();
if (process.argv[2] === "--serve") {
await serve(ctx);
} else {
ctx.dispose();
}