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

Rework Vite plugin to support lightningcss pre processor and fast rebuilds #14269

Merged
merged 6 commits into from
Sep 4, 2024

Conversation

philipp-spiess
Copy link
Member

@philipp-spiess philipp-spiess commented Aug 27, 2024

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 for vite 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.

@philipp-spiess philipp-spiess force-pushed the fix/vite-with-lightningcss-transform branch from fba8ae3 to 4551225 Compare August 27, 2024 14:41
@philipp-spiess philipp-spiess changed the title Vite: Support lightningcss pre processor Vite: Support lightningcss pre processor and simplify plugin Aug 27, 2024
@philipp-spiess philipp-spiess changed the base branch from next to feat/v4-config-files August 27, 2024 14:56
@philipp-spiess philipp-spiess force-pushed the fix/vite-with-lightningcss-transform branch from 4551225 to 43e5170 Compare August 27, 2024 14:56
integrations/utils.ts Outdated Show resolved Hide resolved
@@ -31,13 +31,15 @@
"@tailwindcss/node": "workspace:^",
"@tailwindcss/oxide": "workspace:^",
"lightningcss": "catalog:",
"postcss-load-config": "^6.0.1",
"postcss": "^8.4.41",
Copy link
Member Author

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) {
Copy link
Member Author

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

@philipp-spiess philipp-spiess force-pushed the fix/vite-with-lightningcss-transform branch 3 times, most recently from bf4c01b to 8156548 Compare August 29, 2024 13:31
packages/@tailwindcss-vite/src/index.ts Outdated Show resolved Hide resolved
packages/@tailwindcss-vite/src/index.ts Outdated Show resolved Hide resolved
@philipp-spiess philipp-spiess force-pushed the fix/vite-with-lightningcss-transform branch from 47d9853 to e7bb6b9 Compare August 30, 2024 09:58
@philipp-spiess philipp-spiess changed the title Vite: Support lightningcss pre processor and simplify plugin Rework Vite plugin to support lightningcss pre processor and fast rebuilds Aug 30, 2024
@philipp-spiess philipp-spiess force-pushed the fix/vite-with-lightningcss-transform branch from cbce290 to c4d90d3 Compare August 30, 2024 11:22
@philipp-spiess philipp-spiess marked this pull request as ready for review August 30, 2024 11:23
@philipp-spiess philipp-spiess force-pushed the fix/vite-with-lightningcss-transform branch from 5e5128f to c3ee5c6 Compare August 30, 2024 15:00
@philipp-spiess philipp-spiess marked this pull request as draft September 2, 2024 08:36
@philipp-spiess philipp-spiess marked this pull request as ready for review September 2, 2024 10:09
@philipp-spiess philipp-spiess force-pushed the fix/vite-with-lightningcss-transform branch from 645fb41 to 7f4b079 Compare September 2, 2024 13:27
@philipp-spiess philipp-spiess force-pushed the feat/v4-config-files branch 2 times, most recently from ae63a57 to 3a8dd7a Compare September 2, 2024 13:58
Base automatically changed from feat/v4-config-files to next September 2, 2024 16:03
@thecrypticace thecrypticace force-pushed the fix/vite-with-lightningcss-transform branch from 7f4b079 to 58d5221 Compare September 2, 2024 17:19
@philipp-spiess philipp-spiess force-pushed the fix/vite-with-lightningcss-transform branch from d8c6308 to 53e53ca Compare September 3, 2024 07:56
@philipp-spiess philipp-spiess force-pushed the fix/vite-with-lightningcss-transform branch from 22ef431 to 51e73eb Compare September 3, 2024 15:22
@philipp-spiess philipp-spiess force-pushed the fix/vite-with-lightningcss-transform branch from 51e73eb to 3cc2f08 Compare September 3, 2024 15:25
@philipp-spiess philipp-spiess marked this pull request as draft September 3, 2024 16:32
@philipp-spiess philipp-spiess marked this pull request as ready for review September 4, 2024 08:09
@philipp-spiess philipp-spiess merged commit 8359228 into next Sep 4, 2024
3 checks passed
@philipp-spiess philipp-spiess deleted the fix/vite-with-lightningcss-transform branch September 4, 2024 08:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants