FullHuman/purgecss-webpack-plugin

[attributes] seem to always be included in bundle

qodesmith opened this issue · 2 comments

Hey guys,

Question about [attribute] selectors - are they intended to never be stripped from the final bundle? I noticed that they are always included.

My webpack config - nothing special, just good ol' vanilla purging:

new PurgecssPlugin({
  keyframes: false, // https://goo.gl/bACbDW
  styleExtensions: ['.css'],
  paths: globAll.sync([
    './src/**/*.js',
    './src/**/*.jsx',
    './src/index.ejs'
  ], { absolute: true })
})

I'm using my own scss library called Sassyons which out of the box contains an obnoxious amount of classes. Over 24,000 lines worth! Purgecss successfully strips that library down to only the handful of selectors that are actually used in my test project. So far, so good. Then I add these 2 styles to my top-level scss file to test things out:

.this-is-never-used {
  display: none;
}

[this-is-never-used] {
  display: block;
}

The class is stripped out successfully and not included in the built asset but the attribute selector is included. I'm wondering if this is because attributes can be a pain since they can be regexy like [some-attr*] or [another-attr^=whatever].

Just want to know if this behavior is intended or not. I'm trying to revamp my Purgecss Whitelister plugin and don't know if I should be considering attribute selectors or not since they seem to be included by default. If they aren't supposed to be included by default (i.e. this is indeed a bug), what would be the correct way to whitelist them once this is ironed out? Should the whitelist array contain something like [attribute-name] or attribute-name? I appreciate your help in advance!

Yes, attributes are not stripped from the final bundle.
At the moment, attributes are not consider when removing unused css. If the class associated with the attributes is not used, then it will be removed.

button[disabled=true], this will be removed if button is not found in the content. But it will be kept otherwise. I'll close this issue as FullHuman/purgecss#110 is a duplicate.