Skip to content
This repository has been archived by the owner on Feb 1, 2020. It is now read-only.

[attributes] seem to always be included in bundle #28

Closed
qodesmith opened this issue May 20, 2018 · 2 comments
Closed

[attributes] seem to always be included in bundle #28

qodesmith opened this issue May 20, 2018 · 2 comments

Comments

@qodesmith
Copy link

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!

@Ffloriel
Copy link
Member

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.

@leeoniya
Copy link

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants