-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.ts
More file actions
64 lines (55 loc) · 3.18 KB
/
build.ts
File metadata and controls
64 lines (55 loc) · 3.18 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
// ░░░░░░░░▄▀░█▀▄░█▀▀░█▀▀░█░█░█░░░█▀█░█▀▄░░░░░█░░░█▀█░█░█░█▀█░█░█░▀█▀░▀▄░░░░░░░░
// ░░░░░░░▀▄░░█▀▄░█▀▀░█░█░█░█░█░░░█▀█░█▀▄░▀▀▀░█░░░█▀█░░█░░█░█░█░█░░█░░░▄▀░░░░░░░
// ░░░░░░░░░▀░▀░▀░▀▀▀░▀▀▀░▀▀▀░▀▀▀░▀░▀░▀░▀░░░░░▀▀▀░▀░▀░░▀░░▀▀▀░▀▀▀░░▀░░▀░░░░░░░░░
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
// ┃ * Copyright (c) 2026, the Regular Layout Authors. This file is part * ┃
// ┃ * of the Regular Layout library, distributed under the terms of the * ┃
// ┃ * [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). * ┃
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
import * as esbuild from "esbuild";
import { execSync } from "node:child_process";
const watch = process.argv.includes("--watch");
function generateDeclarations(): void {
console.log("Generating TypeScript declaration files...");
execSync(
"pnpm tsc --project tsconfig.json",
{ stdio: "inherit" }
);
console.log("Declaration files generated!");
}
const browserConfig: esbuild.BuildOptions = {
entryPoints: ["src/index.ts"],
bundle: true,
minify: true,
minifyWhitespace: true,
minifyIdentifiers: true,
outfile: "dist/index.js",
platform: "browser",
format: "esm",
sourcemap: true,
metafile: true,
};
function formatBytes(bytes: number): string {
if (bytes < 1024) return `${bytes} B`;
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(2)} KB`;
return `${(bytes / (1024 * 1024)).toFixed(2)} MB`;
}
async function build(): Promise<void> {
if (watch) {
const browserContext = await esbuild.context(browserConfig);
await browserContext.watch();
console.log("Watching for changes...");
} else {
const result = await esbuild.build(browserConfig);
if (result.metafile) {
console.log("\nBundle Size:");
for (const [file, info] of Object.entries(result.metafile.outputs)) {
console.log(` ${file}: ${formatBytes(info.bytes)}`);
}
}
generateDeclarations();
}
}
build().catch(() => process.exit(1));