@moshyfawn/tailwind-serve
v1.1.0
Published
Compile and serve Tailwind CSS at server startup - no build pipeline needed
Downloads
281
Maintainers
Readme
tailwind-serve
Compile and serve Tailwind CSS at server startup - no build pipeline needed.
For server apps rendering HTML from JSX or templates at runtime (Elysia, Hono, Express, Fastify, Bun.serve()). If you use Vite or Next.js, use @tailwindcss/vite or @tailwindcss/postcss instead.
Install
bun add @moshyfawn/tailwind-serveUsage
Create src/styles.css:
@import "tailwindcss";
@source "./";Then in your server:
import { initTailwind } from "@moshyfawn/tailwind-serve";
const tw = await initTailwind();
// Elysia
app.get("/styles.css", () => tw.response());
// Hono
app.get("/styles.css", (c) => tw.response());
// Bun.serve
if (url.pathname === "/styles.css") return tw.response();Compiles once at startup, watches for changes in dev, caches with immutable headers in production.
API
initTailwind(options?): Promise<TailwindServeInstance>
Returns an instance with:
css- compiled CSS stringresponse()-Responsewithtext/cssand cache headersrebuild()- force recompilationclose()- stop file watchers
compileTailwind(options?): Promise<TailwindCompileResult>
One-shot compile without watching. Returns { css, candidateCount, fileCount }.
Options
| Option | Default | Description |
| -------- | ------------------ | -------------------------------- |
| source | "src/styles.css" | CSS file path relative to base |
| base | process.cwd() | Project root |
Behavior
- Dev (
NODE_ENV !== "production"): watches source directories, recompiles on change, serves withno-cache - Production (
NODE_ENV=production): no watcher, serves withpublic, max-age=31536000, immutable - Source directories and file extensions are derived from
@tailwindcss/oxideScanner - no manual config needed
License
MIT
