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