build-css.ts
Raw
1import { watch } from "fs";
2import { bundle } from "lightningcss";
3
4const INPUT = "src/styles/main.css";
5const OUTPUT = "public/assets/main.css";
6
7async function build() {
8 const { code } = bundle({
9 filename: INPUT,
10 minify: true,
11 sourceMap: false,
12 });
13 await Bun.write(OUTPUT, code);
14 console.log(`[css] built ${code.length} bytes`);
15}
16
17await build();
18
19if (process.argv.includes("--watch")) {
20 watch("src/styles", { recursive: true }, async () => {
21 try {
22 await build();
23 } catch (e) {
24 console.error("[css]", e);
25 }
26 });
27 console.log(`[css] watching src/styles`);
28}
29