Replies: 5 comments 2 replies
-
Hey @molul! You mentioned adding @tailwind directives at the bottom of your src/styles/index.css. Normally, these should be at the top of your CSS file. Ensure your index.css starts with these lines: @tailwind base;
@tailwind components;
@tailwind utilities; And ensure Correct Imports:
|
Beta Was this translation helpful? Give feedback.
-
Thanks for the quick reply, @alex-krasikau. Sorry, I should have explained that more in depth. In index.css, there are only some imports like
...and so on. And according to the docs, @import statements must come first (in fact, I just tried putting the @tailwind lines on top and broke every other style). And regarding the imports, I tried both adding the three @tailwind lines at the end of/src/styles/index.css and adding this line to preview.ts: When I add that line instead of the three @tailwind lines, I can see in Chrome's inspector Network tab that tailwind.css was in fact loaded, but when clicking on the file, I see this content:
which doesn't look right, as in another project where I have Tailwind running correctly, the file is way bigger. More precisely, the fourth line ("const __vite__css = ..."), in the other project, contains all the tailwind styles. The rest is almost the same. The only other different thing is the penultimate line (export default __vite__css), which doesn't exist in the other project's tailwind.css file. Not sure if that might give a hint on where the import is failing to load all the styles. |
Beta Was this translation helpful? Give feedback.
-
Thanks again :) Here's my tailwind.config.js:
postcss.config.js
vite.config.ts:
Tried importing the three files in ".stories/preview.ts" as you suggest (I had to add ".css" to all of them, otherwise they wouldn't be detected), but I'm in the same situation. The three css files are loaded, and if I open them from Chrome's inspector Network tab, I get an almost empty file:
It looks as if "@tailwind" directive wasn't converted to the styles, but just taken as a string. Finally, regarding clearing cache, the only thing I found was deleting the "node_modules/.vite" directory. I did it and then rebuilt the project, but same result :( |
Beta Was this translation helpful? Give feedback.
-
You nailed it! It's working now. Thank you very much ^_^ |
Beta Was this translation helpful? Give feedback.
-
For anyone starting out fresh nowdays after the wizard with npm create vite@latest, follow tailwind instructions, place your import on style.css for tailwind, set your content config on tailwind.config.js finally add vue files support like: so vue key needs to join the band: "./src/**/*.{vue,js,ts,jsx,tsx}", /** @type {import('tailwindcss').Config} */
export default {
content: [
"./index.html",
"./src/**/*.{vue,js,ts,jsx,tsx}",
],
theme: {
extend: {},
},
plugins: [],
} Note: the vue file support enables tailwind without any additional efforts than what official docs say. Posts above might be outdated or prioritize other tools. |
Beta Was this translation helpful? Give feedback.
-
I'm starting to work in a project with Vue+Vite and Storybook, and I'm trying to add Tailwind.
The project has the following structure (leaving only the important files/folders):
.storybook
|--main.ts
|--preview.ts
src
|--components
|--styles
|--index.css
stories
|--(several folders for all stories)
I've installed Tailwind following the Vite+Vue instructions (https://tailwindcss.com/docs/guides/vite#vue).
For step 4, I added the @tailwind base; @tailwind components; and @tailwind utilities; at the bottom "src/styles/index.css" (it contains some css imports, and then at the end I call @tailwind styles), which is called by ".stories/preview.ts".
However, Tailwind classes are not loaded.
I was able to make it work somehow by building the css ("npx tailwindcss -o tailwind.css", then moved this css to "src/styles", then imported it in "src/styles/index.css"), but of course that's not the way to do it.
Can't find any proper instructions to make Tailwind work in a project like this (even in Storybook website). I've tried adding storybook/addon-postcss to ".stories/main.ts" like this:
Also tried defining "content" in tailwind.config.js like this:
content: ['./index.html', './src/**/*.{vue,js,ts,jsx,tsx}', './stories/**/*.{vue,js,ts,jsx,tsx}'],
And adding postcss-import to postcss.config.js like this:
So far, no luck. If anyone has some hint, it would be greatly appreciated :)
Beta Was this translation helpful? Give feedback.
All reactions