-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ts
More file actions
45 lines (38 loc) · 1.15 KB
/
build.ts
File metadata and controls
45 lines (38 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env bun
import { existsSync } from "node:fs";
import { cp, rm } from "node:fs/promises";
import path from "node:path";
import plugin from "bun-plugin-tailwind";
const outdir = path.join(process.cwd(), "dist");
const entrypoints = [path.resolve("src/index.html")];
if (existsSync(outdir)) {
console.log(`Cleaning up previous build...`);
await rm(outdir, { recursive: true, force: true });
}
// Build the application
const start = performance.now();
const result = await Bun.build({
entrypoints,
outdir,
target: "browser",
minify: true,
sourcemap: "linked",
env: "PUBLIC_*",
define: {
"process.env.NODE_ENV": JSON.stringify("production"),
},
plugins: [plugin],
});
const end = performance.now();
const outputTable = result.outputs.map((output) => ({
File: path.relative(process.cwd(), output.path),
Type: output.kind,
Size: `${(output.size / 1024).toFixed(2)} KB`,
}));
console.table(outputTable);
console.log(`🚀 Build Time: ${(end - start).toFixed(2)}ms`);
// Copy the public directory
const publicDir = path.join(process.cwd(), "public");
if (existsSync(publicDir)) {
await cp(publicDir, path.join(outdir, "assets"), { recursive: true });
}