build-css.ts
| 1 | import { watch } from "fs"; |
| 2 | import { transform } from "lightningcss"; |
| 3 | |
| 4 | const INPUT = "src/styles/main.css"; |
| 5 | const OUTPUT = "public/assets/main.css"; |
| 6 | |
| 7 | async 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 | |
| 19 | await build(); |
| 20 | |
| 21 | if (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 |