Replies: 5 comments 9 replies
-
|
You may need to set However, |
Beta Was this translation helpful? Give feedback.
-
|
You can probably just use Some code to poke around at: |
Beta Was this translation helpful? Give feedback.
-
|
Hey @MickL, did you find a solution? I'm looking for the same thing after upgrading to v4. Thanks! |
Beta Was this translation helpful? Give feedback.
-
|
I solved this by adding the following line to my global css file |
Beta Was this translation helpful? Give feedback.
-
|
@adamwathan Did anything change over the course of this year? May we have capabilities to use Tailwind programmatically now or is it better documented? This is my current solution, it works: import { compile } from 'tailwindcss';
import tailwindStyles from 'tailwindcss/index.css?raw';
let compiler: { build(candidates: string[]): string };
export async function useTailwind(html: string, styles = '@import "tailwindcss";'): Promise<string> {
if (!compiler) {
compiler = await compile(styles, {
loadStylesheet: async (id: string, base: string) => {
if (id === 'tailwindcss') {
return {
path: 'virtual:tailwindcss/index.css',
base,
content: tailwindStyles,
};
}
throw new Error(`can't load stylesheet id:${id} base:${base}`);
},
});
}
const classes = Array.from(html.matchAll(/class\s*=\s*("|')(.*?)\1/g), (m) => m[2])
.flatMap((s) => s.split(/\s+/))
.filter(Boolean);
return compiler.build(classes);
} |
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.
-
I am trying to use Tailwind 4 in my backend code to create dynamic results. Unfortunately I cant make it work, this is what I go so far:
For
contentit tells mecontent does not exist in type PluginOptionsbut the bigger problem is it throws an error because it cant find the css@import "tailwindcss":Stackblitz: https://stackblitz.com/edit/github-u6vrxc-dfzdtw4o?file=routes%2Findex.ts
Beta Was this translation helpful? Give feedback.
All reactions