How to render css from Tailwind 4 in ssr? #4298
Replies: 1 comment
-
Assuming the Tailwind CSS file is located at ... // the rest
import fs from "fs";
import crypto from "crypto";
// Generate a hash for the CSS file to ensure unique asset names
const css = fs.readFileSync("src/styles/app.css");
const cssHash = crypto
.createHash("sha256")
.update(css)
.digest("hex")
.slice(0, 8);
export default defineConfig({
...,
plugins: [
tsConfigPaths({
projects: ["./tsconfig.json"],
}),
tanstackStart({ target: "node-server" }),
tailwindcss(),
],
build: {
rollupOptions: {
output: {
assetFileNames: (assetInfo) => {
if (
assetInfo.names &&
assetInfo.names[assetInfo.names.length - 1] === "app.css"
) {
return `assets/app-${cssHash}.css`;
}
return `assets/[name]-[hash][extname]`;
},
},
},
},
}); The SSR output ( I am using |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Running a fresh create-tsrouter-app with the Tailwind add-on.
Steps:
pnpm start
,I've never had a problem making the server html come styled when using Next.js and Tailwind 3. This might seem minor but in slow connections and with no cache I can easily get a flash of unstyled content.
Beta Was this translation helpful? Give feedback.
All reactions