Files
webstudio/packages/scripts/build-package.ts
T
Bogdan Chadkin 6b761bb000 Replace tsc with esbuild to build packages (#543)
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.
2022-11-29 10:04:25 +03:00

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");
}