CSS attribute selectors are removed even when whitelisted
See original GitHub issuePurgeCSS version: 2.0.5
Code
style.css
.button[disabled] {
opacity: .5;
}
postcss.config.js
const purgecss = require('@fullhuman/postcss-purgecss')
module.exports = {
plugins: [
purgecss({
...
whitelistPatterns: [/.*\[disabled].*/],
})
]
}
Expected Behavior
.button[disabled]
is not removed
Actual Behavior
.button[disabled]
is removed
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:6 (5 by maintainers)
Top Results From Across the Web
How to select HTML element without attribute with CSS?
The first selector selects all a elements that do not have class attribute, the latter one selects all with empty class attribute. The...
Read more >Attribute selectors - CSS: Cascading Style Sheets | MDN
The CSS attribute selector matches elements based on the presence or value of a given attribute.
Read more >Configuration - PurgeCSS
The selectors will be removed even when they are seen as used by PurgeCSS. Even if nav-links and usedClass are found by an...
Read more >Trim unused CSS selectors with PurifyCSS and webpack
To prevent PurifyCSS from removing them from the final CSS, use the whitelist option.
Read more >How to workaround: IE6 does not support CSS "attribute ...
This isn't possible without peppering your HTML with a stack of extraneous class selectors, sadly. I'd recommend designing your site so that your...
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 Free
Top 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
Alright, I got closer to the actual issue.
I found out that the attributes are now more important than before 😉. I had following regex:
and assumed this was the correct behavior, but as the attributes are not handled separately, they were assumed that they do not exist.
Therefore chaging the regex to this:
solved a part of this deal (changing my regex from [A-z0-9-:\/]+ to [A-Za-z0-9-:\/]+.)
Unfortunately I couldn’t find any way how to get the [data-v-*] attributes that nuxt / vue adds during build step, so my only idea to get things working again with scoped css is now to whitelist all data-vs:
whitelistPatterns: [/data-v-.*/],
Well it turned out, here is the conenction back to the original issue of this ticket. Whitelisting of attributes isn’t currently working. I’ve created a PR #279 to fix this. After this PR has landed, following should work (beware to NOT add [ ])
whitelist: ['disabled'],
regards and sorry for so many comments and text 😉 thought maybe it helps to reproduce
PR for whitelisting of attributes has been merged https://github.com/FullHuman/purgecss/pull/279