esbuild: add watching

This commit is contained in:
Starbeamrainbowlabs 2023-03-04 22:11:16 +00:00
parent 418e4344b6
commit ae595b45e6
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
2 changed files with 36 additions and 10 deletions

View file

@ -5,7 +5,8 @@
"main": "src/index.mjs",
"scripts": {
"test": "echo \"No tests have been written yet.\"",
"build": "node ./src/esbuild.mjs"
"build": "node ./src/esbuild.mjs",
"watch": "ES_MODE=\"watch\" node ./src/esbuild.mjs"
},
"repository": {
"type": "git",

View file

@ -57,10 +57,8 @@ async function do_html() {
}
}
(async () => {
"use strict";
const result = await esbuild.build({
function make_context() {
return {
entryPoints: [
"./app.mjs",
"./app.css",
@ -79,10 +77,37 @@ async function do_html() {
".ttf": "file",
},
external: ["fs", "path"],
});
if (result.errors.length > 0 || result.warnings.length > 0)
console.log(result);
plugins: [
{
name: "copy-html",
setup(build) {
build.onEnd(_result => {
do_html();
})
}
}
]
};
}
await do_html();
(async () => {
"use strict";
switch(process.env.ES_MODE ?? "build") {
case "build":
const result = await esbuild.build(make_context());
if (result.errors.length > 0 || result.warnings.length > 0)
console.log(result);
break;
case "watch":
const ctx = await esbuild.context(make_context());
await ctx.watch();
console.log(`>>> Watching for changes`);
break;
}
// await do_html();
// console.log(await esbuild.analyzeMetafile(result.metafile));
})();
})();