postcss-filename-prefix

2.0.0 • Public • Published

postcss-filename-prefix

A PostCSS plugin to prefix classes with corresponding filenames
The idea is to isolate styles in framework components

js-standard-style

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

Acknowledgements

Package Sidebar

Install

npm i postcss-filename-prefix

Weekly Downloads

73

Version

2.0.0

License

MIT

Unpacked Size

5.46 kB

Total Files

4

Last publish

Collaborators

  • cray0000
  • vmakhaev