esbuild: add watching
This commit is contained in:
parent
418e4344b6
commit
ae595b45e6
2 changed files with 36 additions and 10 deletions
|
@ -5,7 +5,8 @@
|
||||||
"main": "src/index.mjs",
|
"main": "src/index.mjs",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"No tests have been written yet.\"",
|
"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": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|
|
@ -57,10 +57,8 @@ async function do_html() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
(async () => {
|
function make_context() {
|
||||||
"use strict";
|
return {
|
||||||
|
|
||||||
const result = await esbuild.build({
|
|
||||||
entryPoints: [
|
entryPoints: [
|
||||||
"./app.mjs",
|
"./app.mjs",
|
||||||
"./app.css",
|
"./app.css",
|
||||||
|
@ -79,10 +77,37 @@ async function do_html() {
|
||||||
".ttf": "file",
|
".ttf": "file",
|
||||||
},
|
},
|
||||||
external: ["fs", "path"],
|
external: ["fs", "path"],
|
||||||
});
|
plugins: [
|
||||||
|
{
|
||||||
|
name: "copy-html",
|
||||||
|
setup(build) {
|
||||||
|
build.onEnd(_result => {
|
||||||
|
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)
|
if (result.errors.length > 0 || result.warnings.length > 0)
|
||||||
console.log(result);
|
console.log(result);
|
||||||
|
break;
|
||||||
|
|
||||||
await do_html();
|
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));
|
// console.log(await esbuild.analyzeMetafile(result.metafile));
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue