You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The class roundedAndRedBorder is used here only to compose the two other classes. Therefore, I think we should not have the class test__roundedAndRedBorder in the output. What do you think?
Reacted by Jason Axelson, Anth Winter, Kyle Warren, cmpsbl, Helton Valentini, Isaac Johnson, Thien Do, Bri Stanback, Mark Penner, Zack Tanner and 17 more
@BaoDelta It's not a bad idea. But, you could use something like cssnano to eliminate the empty classes. Though, it's a good argument that removing empty classes could be added to CSS Module's list of core modules. I can't think of any "unsafe" behavior that would occur.
If I add minimize to css-loader query, the class test__roundedAndRedBorder is not in the style element anymore but is still referenced in styles.roundedAndRedBorder. In addition, if I have a css file with only compose-only classes, then I will have an empty style element in the DOM.
My situation is that I'm using purecss in my project but I want to hide that fact from my React components. They should not know which css framework I'm using so that I can change and tweak the css. Therefore, I have a lot of css modules with compose-only classes like this:
/* Button.css */.button{composes: pure-button from global;}
That produces a lot of empty and unused real classes.
@joeybaker I want to have styles.roundedAndRedBorder but I expect it to be just "test__roundedBorder test__redBorder" instead of "test__roundedAndRedBorder test__roundedBorder test__redBorder"
I agree, we have many levels of composition in our themed components and we end up with 5 or 6 empty classes and empty classes on the element attributes. The minimize flag on css loader DOES remove them from the CSS, but they are not removed from the HTML when its rendered. It would make our DOM considerably smaller to have these unused classes removed. Is there any way to achieve this?
Is it not possible to use getLocalIdent for this? It must be able to evaluate if the declaration is empty but I have had no luck finding out how to yet.
Activity
joeybaker commentedon Mar 22, 2016
@BaoDelta It's not a bad idea. But, you could use something like cssnano to eliminate the empty classes. Though, it's a good argument that removing empty classes could be added to CSS Module's list of core modules. I can't think of any "unsafe" behavior that would occur.
BaoDelta commentedon Mar 22, 2016
Thanks for your answer @joeybaker
If I add
minimizeto css-loader query, the classtest__roundedAndRedBorderis not in the style element anymore but is still referenced instyles.roundedAndRedBorder. In addition, if I have a css file with only compose-only classes, then I will have an empty style element in the DOM.My situation is that I'm using purecss in my project but I want to hide that fact from my React components. They should not know which css framework I'm using so that I can change and tweak the css. Therefore, I have a lot of css modules with compose-only classes like this:
That produces a lot of empty and unused real classes.
joeybaker commentedon Mar 22, 2016
Hmm… why wouldn't you want to have
styles.roundedAndRedBorder? That's the shortcut CSS Modules gives you for referencing both classes at once, no?BaoDelta commentedon Mar 22, 2016
@joeybaker I want to have
styles.roundedAndRedBorderbut I expect it to be just"test__roundedBorder test__redBorder"instead of"test__roundedAndRedBorder test__roundedBorder test__redBorder"joeybaker commentedon Mar 22, 2016
Ah, I see. That's totally fair.
navgarcha commentedon May 11, 2016
+1
richardgorman commentedon Dec 9, 2016
Is there any progress on this?
tivac commentedon Dec 9, 2016
I've been doing that in
modular-cssand it's really nice. 👍Benno007 commentedon Mar 9, 2017
I agree, we have many levels of composition in our themed components and we end up with 5 or 6 empty classes and empty classes on the element attributes. The minimize flag on css loader DOES remove them from the CSS, but they are not removed from the HTML when its rendered. It would make our DOM considerably smaller to have these unused classes removed. Is there any way to achieve this?
nicksyndicate commentedon May 22, 2017
A lot of empty class names rendered in html, anybody PR ?
[-]Should compose-only classes be hidden?[/-][+]Eliminating unused classes[/+]bitttttten commentedon Jul 28, 2018
Is it not possible to use
getLocalIdentfor this? It must be able to evaluate if the declaration is empty but I have had no luck finding out how to yet.feat: add option to omit locals with empty declaration blocks
feat: add option to omit locals with empty declaration blocks
feat: add option to omit locals with empty declaration blocks
felixsanz commentedon Jul 29, 2021
5 years old, has anyone come up with a solution?
sjoqvist commentedon Aug 16, 2021
@felixsanz Yes, I have proposed a solution (css-modules/postcss-modules-scope#32). It's currently being reviewed by @alexander-akait. If it's approved, then an option should also be added to
css-loaderto enable the feature.alexander-akait commentedon Aug 16, 2021
Yep, need to find time on review 😞 still in my TODO
GitProdEnv commentedon Feb 2, 2022
Any update on this?
zzuieliyaoli commentedon Mar 25, 2025
hi guys, any update on this?
malinindev commentedon Jun 26, 2025
Hey guys, I've created a package for detecting unused css - it provides a simple cli command.
Please check it out: https://www.npmjs.com/package/check-unused-css