More resilient esbuild
This commit is contained in:
parent
762f890f41
commit
d419d7a9b0
70
esbuild.js
70
esbuild.js
@ -6,6 +6,45 @@ const chokidar = require("chokidar");
|
|||||||
|
|
||||||
const watch = process.argv.includes("--watch");
|
const watch = process.argv.includes("--watch");
|
||||||
|
|
||||||
|
async function build_scss(watch) {
|
||||||
|
let scss_build;
|
||||||
|
if (watch) {
|
||||||
|
const scss_watcher = chokidar.watch("src", { ignoreInitial: true });
|
||||||
|
scss_watcher.on("all", (_, path) => {
|
||||||
|
if (!scss_build) return;
|
||||||
|
if (path.endsWith(".scss") && !path.endsWith("/includes.scss")) {
|
||||||
|
// refresh the list of all scss files in includes.scss
|
||||||
|
spawn("./node_modules/.bin/sealgen", ["generate-scss-includes"]).on(
|
||||||
|
"close",
|
||||||
|
() => {
|
||||||
|
try {
|
||||||
|
scss_build.rebuild();
|
||||||
|
console.log(`Built main.scss [on ${path}]`);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
setTimeout(() => {
|
||||||
|
scss_build
|
||||||
|
.rebuild()
|
||||||
|
.catch((e) => conslole.error(e.message));
|
||||||
|
}, 200);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
scss_build = await build({
|
||||||
|
entryPoints: ["./src/main.scss"],
|
||||||
|
sourcemap: true,
|
||||||
|
outfile: "./public/dist/style.css",
|
||||||
|
logLevel: "info",
|
||||||
|
incremental: watch,
|
||||||
|
plugins: [sassPlugin()],
|
||||||
|
});
|
||||||
|
scss_build.rebuild();
|
||||||
|
}
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const entryPoints = await glob("./src/back/**/*.ts");
|
const entryPoints = await glob("./src/back/**/*.ts");
|
||||||
build({
|
build({
|
||||||
@ -18,15 +57,6 @@ const watch = process.argv.includes("--watch");
|
|||||||
target: "node16",
|
target: "node16",
|
||||||
format: "cjs",
|
format: "cjs",
|
||||||
});
|
});
|
||||||
const scss_build = await build({
|
|
||||||
entryPoints: ["./src/main.scss"],
|
|
||||||
sourcemap: true,
|
|
||||||
outfile: "./public/dist/style.css",
|
|
||||||
logLevel: "info",
|
|
||||||
incremental: watch,
|
|
||||||
plugins: [sassPlugin()],
|
|
||||||
});
|
|
||||||
scss_build.rebuild();
|
|
||||||
|
|
||||||
build({
|
build({
|
||||||
entryPoints: ["./src/front/index.ts"],
|
entryPoints: ["./src/front/index.ts"],
|
||||||
@ -37,23 +67,9 @@ const watch = process.argv.includes("--watch");
|
|||||||
watch,
|
watch,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (watch) {
|
try {
|
||||||
const scss_watcher = chokidar.watch("src", { ignoreInitial: true });
|
await build_scss(watch);
|
||||||
scss_watcher.on("all", (_, path) => {
|
} catch (e) {
|
||||||
if (path.endsWith(".scss")) {
|
console.error(e.message);
|
||||||
// refresh the list of all scss files in includes.scss
|
|
||||||
spawn("./node_modules/.bin/sealgen", ["generate-scss-includes"]).on(
|
|
||||||
"close",
|
|
||||||
() => {
|
|
||||||
scss_build.rebuild().catch(async (e) => {
|
|
||||||
console.error(e);
|
|
||||||
setTimeout(() => {
|
|
||||||
scss_build.rebuild();
|
|
||||||
}, 200);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user