Refactor build process to use NOWATCH constant for conditional logic
This commit is contained in:
parent
770b1e9f06
commit
5b0716930f
1 changed files with 5 additions and 3 deletions
8
index.ts
8
index.ts
|
@ -6,6 +6,8 @@ import { join } from "node:path";
|
||||||
|
|
||||||
const glob = new Glob("**/*");
|
const glob = new Glob("**/*");
|
||||||
|
|
||||||
|
const NOWATCH = process.env.NOWATCH === "1";
|
||||||
|
|
||||||
const build = async () => {
|
const build = async () => {
|
||||||
const start = Date.now();
|
const start = Date.now();
|
||||||
const built = await Bun.build({
|
const built = await Bun.build({
|
||||||
|
@ -15,10 +17,10 @@ const build = async () => {
|
||||||
experimentalCss: true,
|
experimentalCss: true,
|
||||||
splitting: true,
|
splitting: true,
|
||||||
sourcemap: "linked",
|
sourcemap: "linked",
|
||||||
...(process.env.NOWATCH === "1" ? {minify: true} : {})
|
...(NOWATCH ? {minify: true} : {})
|
||||||
});
|
});
|
||||||
const end = Date.now();
|
const end = Date.now();
|
||||||
//await cleanOldFiles(built.outputs);
|
if (NOWATCH) await cleanOldFiles(built.outputs);
|
||||||
console.log("Did build", built.success, built.logs);
|
console.log("Did build", built.success, built.logs);
|
||||||
console.log("Build time:", end - start, "ms");
|
console.log("Build time:", end - start, "ms");
|
||||||
};
|
};
|
||||||
|
@ -41,7 +43,7 @@ const cleanOldFiles = async (outputs: BuildArtifact[]) => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (process.env.NOWATCH !== "1") {
|
if (!NOWATCH) {
|
||||||
watch(import.meta.dir, { recursive: true }, async (_, file) => {
|
watch(import.meta.dir, { recursive: true }, async (_, file) => {
|
||||||
if (!file?.startsWith("dist")) return await build();
|
if (!file?.startsWith("dist")) return await build();
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Reference in a new issue