Removing/reducing unused --tw css custom variables #13828
-
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
You could set module.exports = {
experimental: {
optimizeUniversalDefaults: true, |
Beta Was this translation helpful? Give feedback.
-
You might find this article I wrote a few years ago interesting: https://adamwathan.me/composing-the-uncomposable-with-css-variables/ It explains in detail how the empty variable stuff works and what we use it for 👍 We have to set it on every single element ( Consider a simplified example of some of what Tailwind does: * {
--tw-translate-x: ;
--tw-translate-y: ;
}
.translate-x-4 {
--tw-translate-x: translateX(1rem);
transform: var(--tw-translate-x) var(--tw-translate-y);
}
.translate-y-8 {
--tw-translate-x: translateX(2rem);
transform: var(--tw-translate-x) var(--tw-translate-y);
} Now consider this markup: <div class="translate-x-4">
<!-- ... -->
<!-- Somewhere way deeper... -->
<div class="translate-y-8">...</div>
<!-- ... -->
</div> If we set the variables on In v4 we're using the new Generally I wouldn't worry about actually trying to reduce this stuff — even though it's applied to every element it only appears once in your CSS file. The |
Beta Was this translation helpful? Give feedback.
-
Excellent, thank you so much for the robust explanation and tips! |
Beta Was this translation helpful? Give feedback.
-
If you're using purgeCss, remember to safelist |
Beta Was this translation helpful? Give feedback.
You might find this article I wrote a few years ago interesting:
https://adamwathan.me/composing-the-uncomposable-with-css-variables/
It explains in detail how the empty variable stuff works and what we use it for 👍 We have to set it on every single element (
*
) rather than:root
because CSS variables are inherited, and we need to make sure that they are reset for every element otherwise you get unexpected results.Consider a simplified example of some of what Tailwind does: