Ignore @tailwind utilities inside @reference
#17836
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
You can use
@reference "tailwindcss"or@reference "../path/to/your/css/file.css"to reference your theme for use in@apply,theme(…), etc…Unfortunatley, because the imported file still contains
@tailwind utilitiesit would trigger a re-scan of the filesystem — even though the use of@referenceensures that no CSS can actually be output by the import itself.This PR does two things:
@tailwind utilitiesinside of@referenceso it isn't a trigger for file scanningBecause of how Vite itself handles dependencies editing files on disk will still trigger a rebuild of any file using
@reference. This is because Vite rebuilds files when any of its transitive dependencies change.For example, given this Vue file:
And this stylesheet:
The dependency chain looks like this:
file.vue -> styles.css -> {all the sources in your project}Vite sees that a file (e.g.
index.html) has changed, thusstyles.cssneeds change, which meansfile.vueneeds to be compiled again as well. Now in reality we depend on the on disk version of styles.css not the compiled version but Vite itself doesn't know that (or have a way to indicate this afaik).Coming up with a solution to that problem will have to be a separate PR — but there is a workaround:
1. Inline the imports from
@import "tailwindcss";Replace this in your main stylesheet:
with this (this is basically what
node_modules/tailwindcss/index.cssis):2. Split your stylesheet into "main" and "theme" parts
Your "theme" is comprised of the
@import 'tailwindcss/theme' layer(theme);import, any custom@themeblocks, any@configdirectives, and any@plugindirectives. Move all of these into their own file.For example, replace this with two files:
with a theme file:
and your main CSS file:
3. Import only your "theme" file in your Vue components / CSS modules / etc…
Fixes #17693