Watch CSS module files for changes #17467
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.
This PR is a follow-up PR for: #17433
In the other PR we allow scanning CSS files for extracting usages of CSS variables. This is important for
.module.cssfiles that reference these variables but aren't in the same big AST of the main CSS file.This PR also makes sure to watch for changes in those registered CSS files and re-extract the variables when they change.
This PR took a bit longer than expected because I was trying to make sure that writing to
./dist/out.cssworks without infinite-looping (e.g.: we had issues with this in Tailwind CSS v3 with webpack).But I couldn't reproduce the issue at all. I did had some code that tried to detect if the CSS file contained license headers and skip in (because then it's very likely an output CSS file) but even without it the tests were fine.
I setup integration tests with
@tailwindcss/cliitself, and with tools that use webpack. Added a test for Next.js, and a dedicated webpack test as well.Even without tests, locally, I couldn't reproduce an infinite loop due to changes in an output CSS file...
Eventually dropped the code that tries to detect output CSS files.
One thing to keep in mind is that if you change any of your "main" CSS files, then we will trigger a full rebuild anyway, so this change is only required for unrelated CSS files (like CSS module files) that use CSS variables.
Test plan