Skip to content
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

Watch CSS module files for changes #17467

Merged
merged 9 commits into from
Mar 31, 2025
Merged

Conversation

RobinMalfait
Copy link
Member

@RobinMalfait RobinMalfait commented Mar 31, 2025

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.css files 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.css works 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/cli itself, 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

  1. Added integration tests for the CLI and Next.js
  2. Added new dedicated test for webpack

@RobinMalfait RobinMalfait requested a review from a team as a code owner March 31, 2025 15:00
@RobinMalfait RobinMalfait changed the title Watch CSS files for changes Watch CSS module files for changes Mar 31, 2025
Copy link
Contributor

@thecrypticace thecrypticace left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤞 we get no build loops lol

},
}
`,
'webpack.config.js': js`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might want to try what happens if you enable https://webpack.js.org/configuration/output/#outputclean

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Luckily that didn't make a difference, but also annoying that I can't reproduce it haha. 923c98f

Copy link
Member

@philipp-spiess philipp-spiess left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going to mark this as "request changes" for now because in #17412 the repro also needed the emptyOutDir vite option so it would be good to test with the clean webpack option.

@RobinMalfait RobinMalfait merged commit 5380109 into main Mar 31, 2025
7 checks passed
@RobinMalfait RobinMalfait deleted the fix/watch-other-css-files branch March 31, 2025 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants