Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Feature Suggestion: "Exclude" option #6

Open
gmhenderson opened this issue Jan 16, 2019 · 3 comments
Open

Feature Suggestion: "Exclude" option #6

gmhenderson opened this issue Jan 16, 2019 · 3 comments

Comments

@gmhenderson
Copy link

Hello. Thank you for the very useful plugin. In my case, however, I needed the ability to exclude certain selectors from receiving the prefix. I modified the code a bit and added an exclude option, which should be an array of RegExp's against which to test the selectors, before prepending anything:

...

var selectorExcluded = function (regexp) {
  return regexp.test(selector)
}

if (selector.startsWith(opts.selector.trim()) || opts.exclude.some(selectorExcluded)) {
  return selector
}

return opts.selector + selector

...

which could be used like:

require('postcss-prepend-selector')({ selector: '.my-stuff ', exclude: [/#content-wrapper/] })

It seems to be working, so I thought I'd share the idea in case you're interested in incorporating into the plugin.

@ledniy
Copy link
Owner

ledniy commented Jan 20, 2019

@gmhenderson Thanks for suggesting, I will try to get into it on weekends, or maybe you want to create PR with that change and test cases of it?

@christianmagill
Copy link

This definitely seems super useful. I'd love to see it incorporated.

@dannyuk1982
Copy link

dannyuk1982 commented Jun 27, 2022

I know this is old, but to save anyone else who comes across this time, this plugin does the same job and has an exclude function https://github.com/RadValentin/postcss-prefix-selector

usage, i.e.

plugins: [require("postcss-prefix-selector")({ prefix: "#app ", exclude: ['html', 'body'] })]

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

No branches or pull requests

4 participants