mirror of
https://github.com/shinyobjectz/raea.git
synced 2026-12-01 12:44:11 -10:00
This repository was an export of a private one; from this commit on it is where raea is developed. Contributions: CONTRIBUTING.md.
19 lines
1.2 KiB
TypeScript
19 lines
1.2 KiB
TypeScript
// bun tw.ts COMP.tsx: the CSS for the Tailwind classes a component uses (Tailwind 4.3.3), for
|
|
// void's `component` tool to put in a <style> beside it (raea-runtime-react's Blitz honours inline <style>, not <link>).
|
|
// Class candidates are every whitespace-separated token in the file's string literals; Tailwind ignores the rest.
|
|
import { compile } from "tailwindcss";
|
|
import { readFileSync } from "fs";
|
|
import { dirname, join } from "path";
|
|
const src = readFileSync(process.argv[2], "utf8");
|
|
const candidates = new Set<string>();
|
|
for (const m of src.matchAll(/(["'`])((?:(?!\1)[^\\]|\\.)*)\1/g)) for (const c of m[2].split(/\s+/)) if (c) candidates.add(c);
|
|
const pkg = dirname(require.resolve("tailwindcss/package.json"));
|
|
const c = await compile('@import "tailwindcss"; @theme { --font-sans: "Inter", sans-serif; }', {
|
|
base: pkg,
|
|
loadStylesheet: async (id: string, base: string) => {
|
|
const file = id === "tailwindcss" ? join(pkg, "index.css") : join(pkg, id.replace(/^tailwindcss\//, ""));
|
|
return { path: file, base: dirname(file), content: readFileSync(file.endsWith(".css") ? file : file + ".css", "utf8") };
|
|
},
|
|
});
|
|
process.stdout.write(c.build([...candidates]));
|