-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
[v4] Vite plugin breaks when setting css.transformer
to "lightningcss"
#14205
Comments
Thanks @philipp-spiess, that narrows down the problem. It's because I was configuring import tailwindcss from "@tailwindcss/vite";
import react from "@vitejs/plugin-react";
import { defineConfig } from "vite";
export default defineConfig({
css: {
transformer: "lightningcss",
},
plugins: [react(), tailwindcss()],
}); If I remove it, everything works as expected! No more mystery problems. This was also breaking a few other features, like using
All of this is resolved by removing that (redundant?) part of the config. I've updated the original bug report. Hopefully you can reproduce this and then decide how to fix it, even if it's just erroring out for now, since "completely broken with a clear error message" is a lot better than "mysteriously half-broken". |
@apply
classescss.transformer
to "lightningcss"
@aaronadamsCA Thank you so much! Yeah, this doesn't work right now 😞 We currently rely on the default
I agree, though, that this is something that should work much better than it does right now. I'll brainstorm some ideas and will get back to you. |
@aaronadamsCA I'll continue to look into it but wanted to give a quick update since we just talked about this. Our current thinking is that For the very short term, this unfortunately means that we won't have a good solution for this and the current alpha releases of |
Sounds good @philipp-spiess! Maybe you could just throw an error if the Vite config is invalid. In the meantime, hopefully anybody who runs into any of the same problems can now find this issue report! |
This works similar to the Vue setup. The styles that Astro will receive might still contain Tailwind CSS APIs but since it's not picky, we can pass that through to the regular Vite `transform` handlers for now. This, however, will have issues like #14205. We have to fix this together with Vue and other similar extensions later. For now, it will break when syntax is used that lightningcss rewrites (like `@apply text-3xl/tight;`) --------- Co-authored-by: Jordan Pittman <jordan@cryptica.me>
Reopening this. It's fixed now for the majority of cases (so normal CSS files going through Vite) but plugins that use the |
Not sure if this should be noted here or in a new issue, but there is currently also an issue with setting lightningcss can handle custom media queries, however Tailwind will throw an error |
@corneliusio Which version of Tailwind CSS and the Tailwind Vite plugin are you on? I was just trying this out with the Tailwind CSS Alpha 23 releases and the following Vite config: import tailwindcss from '@tailwindcss/vite'
import { defineConfig } from 'vite'
export default defineConfig({
css: {
transformer: 'lightningcss',
lightningcss: {
drafts: {
customMedia: true,
},
},
},
plugins: [tailwindcss()],
}) And custom-media queries seem to be correctly transpiled. |
Ah, I'm glad you posted your config. I had missed that I needed to add However, one thing I did discover after making this update that may or may not be an issue that can be addressed is that lightningcss will throw an error if you attempt to use the Tailwind
Edit: Using |
Oh gotcha yes we will need to replace theme inside |
@corneliusio Fixed in #14358 :) |
🙌🏼 Fantastic! Now I just need Bun to get this odd edge case resolve. 🙃 |
Going to close this one as the original issue was resolved. If anyone is still running into any issues related to the |
What version of Tailwind CSS are you using?
4.0.0-alpha.19
What build tool (or framework if it abstracts the build tool) are you using?
Vite 5.4.0
What version of Node.js are you using?
20.16.0
What browser are you using?
N/A
What operating system are you using?
Ubuntu 22.04
Reproduction URL
Let me know if you need this and how you'd like it. It works fine on Tailwind Play but fails in Vite.
Describe your issue
With a Vite config specifies
"lightningcss"
as the CSS transformer:The behaviour of the Vite plugin is undefined and buggy.
It crashes when using
@apply
with class names containing characters*
or/
:It pollutes the console with warnings:
And it seems to ignore
@layer base
classes.You can work around the problem by removing the offending part of the Vite config.
The text was updated successfully, but these errors were encountered: