Skip to content

Commit 97d38aa

Browse files
committed
fix: fixed up plugin serving stuff
1 parent ac688e7 commit 97d38aa

File tree

3 files changed

+44
-18
lines changed

3 files changed

+44
-18
lines changed

.vscode/pack-zip.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ loadFile('', distFolder);
2323

2424
zip
2525
.generateNodeStream({ type: 'nodebuffer', streamFiles: true })
26-
.pipe(fs.createWriteStream(path.join(__dirname, '../AcodeX.zip')))
26+
.pipe(fs.createWriteStream(path.join(distFolder, '/AcodeX.zip')))
2727
.on('finish', () => {
2828
console.log('dist.zip written.');
2929
});
@@ -44,4 +44,4 @@ function loadFile(root, folder) {
4444
zip.file(path.join(root, file), fs.readFileSync(path.join(folder, file)));
4545
}
4646
});
47-
}
47+
}

build.mjs

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,46 @@
11
import * as esbuild from "esbuild";
2-
import {sassPlugin} from 'esbuild-sass-plugin';
2+
import { sassPlugin } from 'esbuild-sass-plugin';
33
import { exec } from 'child_process';
44

5-
let result = await esbuild.build({
6-
entryPoints: ["src/main.js"],
7-
bundle: true,
8-
minify: true,
9-
logLevel: 'info',
10-
color: true,
11-
outdir: "dist",
12-
plugins: [sassPlugin()]
13-
});
5+
const isServe = process.argv.includes("--serve");
146

15-
exec("node .vscode/pack-zip.js", (err, stdout, stderr) => {
7+
let buildConfig = {
8+
entryPoints: ["src/main.js"],
9+
bundle: true,
10+
minify: true,
11+
logLevel: 'info',
12+
color: true,
13+
outdir: "dist",
14+
plugins: [sassPlugin()]
15+
};
16+
17+
// to pack the zip file
18+
function packZip() {
19+
exec("node .vscode/pack-zip.js", (err, stdout, stderr) => {
1620
if (err) {
17-
console.error(err);
18-
return;
21+
console.error("Error packing zip:", err);
22+
return;
23+
}
24+
console.log("Packed zip:", stdout);
25+
});
26+
}
27+
28+
if (!isServe) {
29+
// Production build
30+
let result = await esbuild.build(buildConfig);
31+
32+
// Pack zip after building
33+
packZip();
34+
35+
} else {
36+
// Serve mode with watch and zip packing on rebuild
37+
let ctx = await esbuild.context(buildConfig);
38+
39+
await ctx.watch();
40+
let { host, port } = await ctx.serve({
41+
servedir: "dist",
42+
onRequest: async (args) => {
43+
packZip();
1944
}
20-
console.log(stdout);
21-
});
45+
});
46+
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"jszip": "^3.10.1"
2424
},
2525
"scripts": {
26-
"build": "node build.mjs"
26+
"build": "node build.mjs",
27+
"serve": "node build.mjs --serve"
2728
},
2829
"browserslist": [
2930
"> 0.25%, not dead"

0 commit comments

Comments
 (0)