-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathbuild.ts
39 lines (35 loc) · 989 Bytes
/
build.ts
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
import { build, BuildOptions, context } from "esbuild";
import { spawn } from "child_process";
import { compilerOptions } from "./tsconfig.json";
const dev = process.argv.pop() == "dev";
const alias: Record<string, string> = {};
for (const key in compilerOptions.paths) {
alias[key] =
compilerOptions.paths[key as keyof typeof compilerOptions.paths][0];
}
async function main() {
const options: BuildOptions = {
outdir: "dist",
minify: true,
bundle: true,
sourcemap: true,
entryPoints: ["src/index.tsx"],
external: ["fs", "path"],
loader: {
".png": "file",
".jpg": "file",
".otf": "file",
".gz": "file",
},
alias,
};
if (dev) {
spawn("pnpm", ["run", "uno", "-w"], { stdio: "inherit" });
const buildContext = await context(options);
console.log(await buildContext.serve({ servedir: "dist" }));
} else {
spawn("pnpm", ["run", "uno"], { stdio: "inherit" });
await build(options);
}
}
main();