question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CSS attribute selectors are removed even when whitelisted

See original GitHub issue

PurgeCSS 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:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
simllllcommented, Feb 3, 2020

Alright, I got closer to the actual issue.

I found out that the attributes are now more important than before 😉. I had following regex: image 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: image 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

0reactions
Fflorielcommented, Mar 30, 2020

PR for whitelisting of attributes has been merged https://github.com/FullHuman/purgecss/pull/279

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found