PostCSS plugin that adds custom scopes to selectors.
Before using the plugin, make sure to have installed the PostCSS before:
npm install postcss
After installing postcss you can install the plugin:
npm install postcss-custom-scoper
var postcss = require('postcss'),
scoper = require('postcss-custom-scoper');
var cssFile = fs.readFileSync('path/to/file.css', 'utf-8').toString();
var output1 = postcss().use(
scoper({
{
//multiple matches
selectors: {
'something-to-match' : 'what-to-add',
'*' : 'matches-all'
}
ignore: [ /regex-to-match/, '.class-to-ignore', '#id-to-ignore' ]
}
})
).process(cssFile);
// or
var output2 = postcss().use(
scoper({
{
//first match used
selectors: [
{'something-to-match' : 'what-to-add'},
{'*' : 'matches-all'}
],
ignore: [ /regex-to-match/, '.class-to-ignore', '#id-to-ignore' ]
}
})
).process(cssFile);
See PostCSS docs for examples for your environment.
/* Before */
.foo {
}
/* After */
.foo {
}
Plugin inspired by:
- postcss-selector-namespace create by topaxi
- postcss-prefixer created by marceloucker