-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tailwind classes from client:only components are not included in final builds #13139
Comments
What solves for me with SolidJS is to import the global style in any of the components that is used with the This doesn't solve for css modules loaded from a component that has been used with the What would be great is to be able to set the global style in the Vite plugin itself so you don't need to load it in any other place. For example:
|
Was having the same issue without any framework, just Astro and some Typescript with Tailwind. This appears to also have been raised in the TailwindCSS repository: Specifically, this comment seems to have solved it (at least for me): |
An update here: while this bug was labeled "ecosystem: upstream", it's clear from comments by the tailwind team that this isn't simply an issue with their own tooling:
They describe a workaround for now:
They've opened a discussion with the Astro team to figure out how to tackle this. |
I encountered a similar issue with Vue. In my project, I import the CSS file (which includes Tailwind's directives) in my After some digging through various issues on both the Astro and TailwindCSS repositories, I found a workaround to use the TailwindCSS configuration from version 3.x in version 4. Initially, I solved it by adding the directive: ./src/styles/global.css: @import "tailwindcss";
@config "../../tailwind.config.js"; This approach works, but while reviewing the Tailwind documentation, I discovered a better method that doesn’t require a JS file. Instead, you can simply add this directive to your CSS file: ./src/styles/global.css: @import "tailwindcss" source("../src"); This magically fixes the issue. It seems that the problem is related to how TailwindCSS 4 detects the source files. In my case, since the CSS file (that imports Tailwind) is located in I reached this conclusion after reading the TailwindCSS documentation on detecting classes in source files. If my interpretation is off, please let me know so I can better understand the root cause. I hope this solution helps others facing a similar issue! |
Yes using a source directive works in the meantime |
This should be fixed by Tailwind |
Yep, this seems to be working well now :D |
I'll wait for another confirmation before closing |
LGTM! |
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
A simple astro 5.2 / tailwind 4 / framework UI project.
There's a single
index.astro
page, which includes a react component inBlueBox.tsx
via<BlueBox client:only />
.The tailwind CSS classes from
BlueBox
are culled correctly when usingnpm run dev
; however, the final build output fromnpm run build
does not contain those classes. Culling CSS classes should still be a build-time concern, even forclient:only
components.I'm using the latest tailwind integration (
astro add tailwind
) as described in the 5.2 announcement. I'm using React for the framework UI component, but I wouldn't be surprised if this reproduces with other frameworks, too.Dev builds work as expected:
npm run dev
http://localhost:4321/
Full builds do not:
npm run build
dist/
directory (I usepython -m http.server 8000 --directory dist/
)http://localhost:8000/
Looking at the CSS generated in the full build pass, definitions are missing for the
bg-blue-200
,h-64
andw-64
classes used by theBlueBox
component.Image:
npm run dev
resultsImage:
npm run build
resultsWhat's the expected result?
The expected CSS classes are included in the output of
npm run build
; build and dev should look the same.Link to Minimal Reproducible Example
https://github.com/literalgarage/astro-tailwind-bug (GitHub repo)
https://stackblitz.com/github/literalgarage/astro-tailwind-bug
Participation
The text was updated successfully, but these errors were encountered: