-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Rework Vite plugin to support lightningcss pre processor and fast rebuilds #14269
Conversation
fba8ae3
to
4551225
Compare
4551225
to
43e5170
Compare
@@ -31,13 +31,15 @@ | |||
"@tailwindcss/node": "workspace:^", | |||
"@tailwindcss/oxide": "workspace:^", | |||
"lightningcss": "catalog:", | |||
"postcss-load-config": "^6.0.1", | |||
"postcss": "^8.4.41", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is temporary until we start to resolve @import
ourselves (at this point every client need this so we might as well)
cssPlugins = config.plugins.filter((plugin) => { | ||
return allowedPlugins.includes(plugin.name) | ||
}) | ||
}, | ||
|
||
// Append the postcss-fix-relative-paths plugin | ||
async config(config) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We no longer need this since we can just run our own at-import plugins
bf4c01b
to
8156548
Compare
47d9853
to
e7bb6b9
Compare
cbce290
to
c4d90d3
Compare
5e5128f
to
c3ee5c6
Compare
645fb41
to
7f4b079
Compare
ae63a57
to
3a8dd7a
Compare
7f4b079
to
58d5221
Compare
d8c6308
to
53e53ca
Compare
22ef431
to
51e73eb
Compare
51e73eb
to
3cc2f08
Compare
Fixes #14205
Fixes #14106
This PR reworks the Vite extension in order to supprt
lightningcss
as the pre-processor, enable faster rebuilds, and adds support forvite build --watch
mode. To make this change possible, we've done two major changes to the extension that have caused the other changes.1. Tailwind CSS is a preprocessor
We now run all of our modifications in
enforce: 'pre'
. This means that Tailwind CSS now gets the untransformed CSS files rather than the one already going through postcss or lightningcss. We do this because Tailwind CSS is a preprocessor at the same level as those tools and we do sometimes use the language in ways that creates problems when it's the input for other bundlers.The correct solution here is to make Tailwind not depend on any other transformations. The main reason we were not using the
enforce: 'pre'
phase in Vite before was becuase we relied on the@import
flattening of postcss so we now have to do this manually.@import
flattening is now a concern that every Tailwind V4 client has to deal with so this might actually be something we want to inline into tailwindcss in the future.2. A Vite config can have multiple Tailwind roots
This is something that we have not made very explicit in the previous iteration of the Vite plugin but we have to support multiple Tailwind roots in a single Vite workspace. A Tailwind root is a CSS file that is used to configure Tailwind. Technically, any CSS file can be the input for
tailwindcss
but you have to add certain rules (e.g.@import "tailwindcss";
) to make the compiler do something.A workspace can have multiple of these rules (e.g. by having different Tailwind configures for different sub-pages). With the addition of support for
@source
rules and JS config files, Tailwind roots become more complex and can have a custom list of dependencies (that is other JavaScript modules the compiler includes as part of these new rules). In order to only rebuild the roots we need to, we have to make this separation very clear.