Dynamic classes are purged
See original GitHub issueIn components, you usually have classes added or generated dynamically:
<div :class="{ 'some-class': someCondition }">
Additionally, there are components not rendered in a first render, in particular those that don’t meet the condition in a v-if
directive.
For those, these dynamic classes are purged, breaking the styling of them.
A good solution can be what’s mentioned in this issue about prefixing all Vue classes (for instance, with an underscore) and whitelist them.
Could we make that a default in this module? I think it could improve the DX, since the users don’t need to worry about this or come across the same problem
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Tailiwind, purging & dynamic classes - HEY World
Tailiwind, purging & dynamic classes ... The reason for this is Tailwind using PurgeCSS to delete unused classes and PurgeCSS being ...
Read more >Mix purges my dynamic classes - Laracasts
I have this piece of code in my L8 project: {{ $header }} Obviously, css-purger does not recognize the class and purges my...
Read more >purgecss can't recognize conditional classes - Stack Overflow
PurgeCSS is intentionally very naive in the way it looks for classes in your HTML. It doesn't try to parse your HTML and...
Read more >How to Add Dynamic Generated Classes in Tailwind CSS ...
Learn how to add dynamically generated classes in Tailwind CSS and whitelist it to prevent from being purge.
Read more >Steps for deleting a dynamic CDT class - IBM
If those steps were executed, the SETROPTS options for all classes that share the POSIT value with the deleted class would be deactivated....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey @alexjoverm 👋
PurgeCSS does a string-based comparison approach. So
<div :class="{ 'some-class': someCondition }">
should be detected (and not purged) properly.However, classes live
<div :class="'some-class-'+prop">
won’t be recognized correctly.Unfortunately, there is no ideal solution for that. As you said, prefixing all classes internally won’t purge the unused CSS classes in global files which kills the benefits of PurgeCSS.
I’ve already included the defaults for
body
,html
and thenuxt-*
classes in the whitelist so people don’t have to add them manually as well.But in terms of “generated classes” adding them by hand might be the best option while still keeping all PurgeCSS benefits 🤔
Hey @CurtisBelt! I’m using
whiteListPatterns
in several of my projects and it works well withnuxt-purgecss
. (example)