Skip to content

A Webpack plugin that prefixes classes with custom prefix in css files

License

Notifications You must be signed in to change notification settings

nagendertank/postcss-prefix-webpack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

postcss-prefix-webpack

Webpack plugin to add a prefix to all css selectors classes and ids.

Usage

Install postcss-prefix-webpack on your project directory:

npm install postcss-prefix-webpack --save-dev

Options

input - Input file Path

Type: string
Default: none

output - Output file path

Type: string
Default: none

prefixProperties - Object which has properties: prefix and ignore
prefix

Type: string
Default: none

String to be used as prefix

ignore

Type: array
Default: []

Example

Example of usage with results generated by the plugin.

Code

const PostCSSPrefix = require('postcss-prefix-webpack');

module.exports = {
  entry: 'index.js',
  output: {
    path: __dirname + '/dist',
    filename: 'index_bundle.js'
  },
  plugins: [
   new PostCSSPrefix({
      input:'./src/style.css',
      output: './public/style-prefix.css',
      prefixProperties: {
        prefix: 'prefix-',
        ignore: [/selector-/, '.ignore', '#ignore']
      }
    })
  ]
}

Input:

#selector-one .example {
  /* content */
}

.selector-two .example2 {
  /* content */
}

#ignore .ignore {
  /* content */
}

#ignore .other {
  /* content */
}

Output:

#selector-one .prefix-example {
  /* content */
}

.selector-two .prefix-example2 {
  /* content */
}

#ignore .ignore {
  /* content */
}

#ignore .prefix-other {
  /* content */
}

Recommendation

Credits

Plugin based on

About

A Webpack plugin that prefixes classes with custom prefix in css files

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published