-
Notifications
You must be signed in to change notification settings - Fork 55
/
esbuild.config.mjs
57 lines (49 loc) · 1.2 KB
/
esbuild.config.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
52
53
54
55
56
57
import * as esbuild from "esbuild";
import { exec } from "child_process";
const isServe = process.argv.includes("--serve");
// Function 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(stdout.trim());
});
}
// Custom plugin to pack ZIP after build or rebuild
const zipPlugin = {
name: "zip-plugin",
setup(build) {
build.onEnd(() => {
packZip();
});
},
};
// Base build configuration
let buildConfig = {
entryPoints: ["src/main.js"],
bundle: true,
minify: true,
logLevel: "info",
color: true,
outdir: "dist",
plugins: [zipPlugin],
};
// Main function to handle both serve and production builds
(async function () {
if (isServe) {
console.log("Starting development server...");
// Watch and Serve Mode
const ctx = await esbuild.context(buildConfig);
await ctx.watch();
const { host, port } = await ctx.serve({
servedir: ".",
port: 3000,
});
} else {
console.log("Building for production...");
await esbuild.build(buildConfig);
console.log("Production build complete.");
}
})();