[v4] Vite plugin providing a virtual file can't be resolved from within main CSS file #15167
Replies: 6 comments 3 replies
-
From digging through the source code a bit, it seems that the module resolution is actually done by this bit - if I understand correctly: tailwindcss/packages/@tailwindcss-node/src/compile.ts Lines 201 to 212 in 7b19b00 Does that mean, custom virtual modules are not supported in CSS files? |
Beta Was this translation helpful? Give feedback.
-
Hey! @spaceemotion. Yeah that's right we don't consult the Vite module resolution when resolving imports right now. Two things you can try to work around it:
I agree with you that this is unexpected though and that the Vite plugin should use the Vite module resolution system and not a custom one. |
Beta Was this translation helpful? Give feedback.
-
The SVG-Core version of FontAwesome does not provide a static CSS, as they generate it on the fly based on the config. They usually add the styles when FontAwesome loads, but since we want to build a (mostly) static site, this means that icons would look weird if the JavaScript hasn't loaded yet. For the time being I had it generate a static version, and "hard-coded" an import to that one. Not ideal, but... Thanks for the tip with the postcss alternative, but I think the current workaround will work until the vite plugin supports the additional module resolution :) |
Beta Was this translation helpful? Give feedback.
-
@spaceemotion I was trying to create a reproduction with your code above but it seems that Vite, even without This is using only Vite 6. Were you able to use this feature before you upgraded to Tailwind 4? There is still the need to use the Vite resolver for css modules for issues like #15159 though, but it won't resolve your concrete issue I'm afraid. |
Beta Was this translation helpful? Give feedback.
-
@philipp-spiess thanks for the repo. That is indeed weird. When the virtual module ID is being used from the I have not tested this with a TailwindCSS 3 setup yet, the virtual module is new for this project as we're upgrading the tech in general. I'll do a bit more digging, whether it might be something with the way vite handles CSS files + postcss internals. I also just checked and the issue is also there with Vite v5, so it's not something with the latest v6 beta. |
Beta Was this translation helpful? Give feedback.
-
Okay, so here's what I found:
|
Beta Was this translation helpful? Give feedback.
-
What version of Tailwind CSS are you using?
What build tool (or framework if it abstracts the build tool) are you using?
astro 5.0.0-beta.8
, usingvite 6.0.0-beta.10
What version of Node.js are you using?
v20
What browser are you using?
Chrome/Edge/Brave
What operating system are you using?
Linux/Windows
Reproduction URL
We got the following stylesheet:
The custom vite plugin is quite simple:
We need the fontawesome CSS to be included in the base layer of our CSS, since we want to be able to overwrite some things (like icon size) via the utility classes. We also don't want to include the CSS on every page, and instead have it in the global stylesheet.
Sadly, FontAwesome does not offer a simple static CSS we can use, since the classes are built at run-/build-time.
Describe your issue
I ran
astro dev
with verbose enabled:From what I can tell, the resolving is being handled by tailwind, and not Astro/Vite? I tried to see if there is a way to still make this worth, but not sure why the virtual module isn't being picked up - the same approach (using virtual modules) works without issue in other parts of the pipeline where we just import things into Vue/Astro/JS.
https://stackblitz.com/edit/vite-u8kysb?file=vite.config.mjs (doesn't load inside of stackblitz due to oxide, but has a minimal example)
Beta Was this translation helpful? Give feedback.
All reactions