postcss-replace-values

A PostCSS plugin to replace one color with another

Usage no npm install needed!

<script type="module">
  import postcssReplaceValues from 'https://cdn.skypack.dev/postcss-replace-values';
</script>

README

postcss-replace-values

Install

npm install --save postcss-replace-values

Simple Usage

const postcss = require('postcss');
const replaceValuesPlugin = require('postcss-replace-values');

postcss()
  .use(replaceValuesPlugin({ 
    values: {
      '#000': '#a00'
    }
  }))

Input CSS:

body {
  color: #000;
}

Output CSS:

body {
  color: #a00;
}

Regex Usage

Only if the selector is matching the regex, the value will be replaced.

const postcss = require('postcss');
const replaceValuesPlugin = require('postcss-replace-values');

postcss()
  .use(replaceValuesPlugin({ 
    values: {
      '#000': { value: '#a00', selector: /btn/ }
    }
  }))

Input CSS:

body {
  color: #000;
}
.btn {
  color: #000;
}

Output CSS:

body {
  color: #000;
}
.btn {
  color: #a00;
}

License

MIT