-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
build.mjs
46 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
import * as esbuild from "esbuild";
import { sassPlugin } from 'esbuild-sass-plugin';
import { exec } from 'child_process';
const isServe = process.argv.includes("--serve");
let buildConfig = {
entryPoints: ["src/main.js"],
bundle: true,
minify: true,
logLevel: 'info',
color: true,
outdir: "dist",
plugins: [sassPlugin()]
};
// to pack the zip file
function packZip() {
exec("node .vscode/pack-zip.js", (err, stdout, stderr) => {
if (err) {
console.error("Error packing zip:", err);
return;
}
console.log("Packed zip:", stdout);
});
}
if (!isServe) {
// Production build
let result = await esbuild.build(buildConfig);
// Pack zip after building
packZip();
} else {
// Serve mode with watch and zip packing on rebuild
let ctx = await esbuild.context(buildConfig);
await ctx.watch();
let { host, port } = await ctx.serve({
servedir: "dist",
onRequest: async (args) => {
packZip();
}
});
}