[v4] Removing/Disable an existing @custom-variant
from production CSS
#16900
Replies: 2 comments 1 reply
-
I don't think there's anyway to remove it. The code for tailwindcss/packages/tailwindcss/src/index.ts Lines 266 to 335 in 595b88f And I don't see any code path where it removes any variants. |
Beta Was this translation helpful? Give feedback.
-
The question may arise as to why I am using class names with the Although the compiled CSS could be processed later with an external tool to remove unnecessary code, why should we struggle with it individually when a restriction could be implemented directly in TailwindCSS? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Is there a way to disable a previously created
@custom-variant
to prevent it from being included in production unnecessarily if I don't need it?Inspired by: How to disable dark mode in TailwindCSS 4 - however I'm interested not only in dark mode but in any previously declared
@custom-variant
, including dark mode itself.Here, the dependency uses dark mode and has declared
dark:
classes as well. As a result, the styles fordark:
classes will be included in production alongside the default classes - unnecessarily. Even if I override it with@custom-variant
as suggested in the answer, the class will still be included in the production CSS unnecessarily.TailwindCSS v4 Playground
What I can imagine for disabling it:
false
,disabled
,none
; perhapsnone
fits the best?Now generated CSS will be:
However expected result:
Beta Was this translation helpful? Give feedback.
All reactions