No, it is not related to a problem I've experienced with the module.
Note: I'm mainly spitballing here. I'm thinking about experimenting with something similar, and wanted to raise this before some more knowledgeable folks.
It might be nice if you could figure out a way to purge the CSS or JIT, based on the html content available to the nitro render:html
hook. Not only would CSS files be smaller, but this would actually enabled using factory patterns for building tailwindcss classnames--something you can't currently do if you want to have reasonable build sizes.
The biggest problem here would be that the postcss.process()
has to take place every render. I'm not sure how significant the performance impacts of doing as much are.
From this package, it would likely need to be something that writes a ~/server/plugins/tailwindcssSsr.ts
plugin. Solution with the best performance wins.
I don't think there are good alternatives.
I'm going to ask about this in tailwindcss discussions as well.
This is sub 100 ms for me on most of my pages:
import tailwindcss from "tailwindcss"
import postcss from "postcss";
import process from "process";
import path from "path";
import fs from "fs";
import config from "../../tailwind.config.js";
// const css = fs.readFileSync(path.join(process.cwd(), "./path/to/main.css")).toString();
export default defineNitroPlugin((nitroApp)=>{
nitroApp.hooks.hook("render:html", async (html, { event })=>{
const t0 = performance.now();
const renderedCss = await postcss([
tailwindcss({
...config,
content : [{ raw : html.body.join()}]
})
]).process(
fs.readFileSync(path.join(process.cwd(), "./path/to/main.css")).toString() // OR css
);
html.body.push(
`<style>
${renderedCss.css}
</style>`
);
const t1 = performance.now();
console.log(t1-t0);
})
});
Loading the CSS once (in module scope)--which should be the correct way to do this in most use cases--seems to reduce hook time by about 50%.
Owner Name | nuxt-modules |
Repo Name | tailwindcss |
Full Name | nuxt-modules/tailwindcss |
Language | TypeScript |
Created Date | 2019-04-04 |
Updated Date | 2023-03-29 |
Star Count | 1285 |
Watcher Count | 12 |
Fork Count | 157 |
Issue Count | 57 |
Issue Title | Created Date | Updated Date |
---|