postcss-filename-prefixes

0.3.8 • Public • Published

Forked from here

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-prefixes

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 delimeter option

By default delimeter between prefix and class is dash character. You can setup any string like:

filenamePrefix({delimeter: '__'})

Using the lowerCase option

Force using of lowecased prefix:

filenamePrefix({lowerCase: true})

Using the ignoreRoot option

Omit .root class

Using the ignoreLowerCasedFileName option

Allow to use lowercase name for css file

filenamePrefix({ignoreRoot: true})

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-prefixes

Weekly Downloads

5

Version

0.3.8

License

MIT

Last publish

Collaborators

  • viktortsarevskiy