mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-11-07 12:33:36 +09:00
Build of whole monorepo without cache takes 1min or more on my laptop. tsc is very slow tool for this. Also having rootDir in tsconfig prevents checking outside of src folder. Here I added "scripts" package with "build-package" bin. It does both esm and cjs builds. --watch flag support completely replaces tsup for us. Now full rebuild of monorepo without cache takes only 10s including prisma-client, http-client and designer builds.
63 lines
1.2 KiB
TypeScript
Executable File
63 lines
1.2 KiB
TypeScript
Executable File
#!/usr/bin/env tsx
|
|
|
|
import { rm, cp } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { totalist } from "totalist";
|
|
import { build } from "esbuild";
|
|
|
|
const args = process.argv.slice(2);
|
|
const watch = args.includes("--watch");
|
|
|
|
const entryPoints: string[] = [];
|
|
const assets: string[] = [];
|
|
|
|
await totalist("./src", (rel) => {
|
|
if (rel.endsWith(".ts") || rel.endsWith(".tsx")) {
|
|
if (rel.includes(".test.") || rel.includes(".stories.")) {
|
|
return;
|
|
}
|
|
entryPoints.push(join("src", rel));
|
|
}
|
|
if (rel.endsWith(".json")) {
|
|
assets.push(rel);
|
|
}
|
|
});
|
|
|
|
await rm("lib", { recursive: true, force: true });
|
|
|
|
await build({
|
|
entryPoints,
|
|
outdir: "lib",
|
|
format: "esm",
|
|
watch: watch && {
|
|
onRebuild(error) {
|
|
if (error) {
|
|
console.error("watch build failed:", error);
|
|
} else {
|
|
console.info("watch build succeeded");
|
|
}
|
|
},
|
|
},
|
|
});
|
|
|
|
await build({
|
|
entryPoints,
|
|
outdir: "lib/cjs",
|
|
format: "cjs",
|
|
outExtension: {
|
|
".js": ".cjs",
|
|
},
|
|
watch,
|
|
});
|
|
|
|
for (const rel of assets) {
|
|
await cp(join("src", rel), join("lib", rel));
|
|
await cp(join("src", rel), join("lib/cjs", rel));
|
|
}
|
|
|
|
if (watch) {
|
|
console.info("watching...");
|
|
} else {
|
|
console.info("build succeeded");
|
|
}
|