postcss-filename-prefix
v2.0.0
Published
Postcss plugin for prefixing classes with corresponding filenames
Downloads
309
Readme
postcss-filename-prefix
A PostCSS plugin to prefix classes with corresponding filenames
The idea is to isolate styles in framework components
MyComponent.css
.myclass { /* ... */ }
.-mymodifier { /* ... */ }
.Mycapitalclass { /* ... */ }
Output:
.MyComponent-myclass { /* ... */ }
.-mymodifier { /* ... */ }
.Mycapitalclass { /* ... */ }
Ignores:
- filenames that starts from not capital letter
- modifiers (classes that starts from hyphen)
- classes that starts from capital letter
Installation
npm install postcss-filename-prefix
Usage
var fs = require('fs');
var postcss = require('postcss');
var filenamePrefix = require('postcss-filename-prefix');
var css = fs.readFileSync('css/MyFile.css', 'utf8').toString();
var out = postcss()
.use(filenamePrefix())
.process(css);
Using the ignore
option
var fs = require('fs');
var postcss = require('postcss');
var filenamePrefix = require('postcss-filename-prefix');
var css = fs.readFileSync('css/MyFile.css', 'utf8').toString();
var out = postcss()
.use(filenamePrefix({ ignore: [/ng-/, 'some-class-to-ignore']}))
.process(css);
License
MIT
Recommendation
- Use it with react-prefix-loader for React components
Acknowledgements
- Inspired by postcss-class-prefix