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

Process Tailwind output with Vite CSS plugins #13218

Merged
merged 14 commits into from
Mar 22, 2024
Merged

Conversation

KrisBraun
Copy link
Contributor

@KrisBraun KrisBraun commented Mar 12, 2024

Transform Tailwind-generated CSS with Vite CSS plugins. vite:css does useful things like transforming url() paths and inlining images. vite:css-post generates bundle hashes. Before this change, the CSS bundle hash wasn't changing when the generated CSS changed.

@KrisBraun
Copy link
Contributor Author

@ArnaudBarre I'm interested in your review here. In particular, do you see any cases where this won't work with other plugins correctly?

@ArnaudBarre
Copy link

Answered in Discord: this way of doing things doesn't make the CSS hash independent of the utils content. To workaround that I found that calling again the transform function of the vite:css-post plugin with the same id but the new content gives expected result, without the need for a fake id or placeholder. It will automatically apply all the transformation from Vite (but not from other plugins, which is fine IMO)

@KrisBraun KrisBraun changed the title Process Tailwind output with other Vite plugins Process Tailwind output with Vite CSS plugins Mar 22, 2024
@KrisBraun
Copy link
Contributor Author

@ArnaudBarre The PR has been updated to apply the renderChunk technique.

packages/@tailwindcss-vite/src/index.ts Outdated Show resolved Hide resolved
packages/@tailwindcss-vite/src/index.ts Outdated Show resolved Hide resolved
playgrounds/vite/vite.config.js Outdated Show resolved Hide resolved
@thecrypticace
Copy link
Contributor

Some small changes but otherwise looks good and appears to work quite well. 💯

KrisBraun and others added 12 commits March 22, 2024 13:27
We were using setTimeout to wait for the initial scan to complete before generating Tailwind CSS. Now that full builds wait until the bundle stage, dev builds can simply run immediately. This might generate Tailwind CSS twice, generating a FOUC, but will be faster than waiting for the timeout.

A [proposed Vite change](vitejs/vite#16135) could address the FOUC and extra build.
Co-authored-by: Jordan Pittman <jordan@cryptica.me>
Co-authored-by: Jordan Pittman <jordan@cryptica.me>
@KrisBraun KrisBraun merged commit 3249777 into next Mar 22, 2024
1 check passed
@KrisBraun KrisBraun deleted the feat/other-vite-plugins branch March 22, 2024 18:57
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.

None yet

3 participants