postcss-colors-json

PostCSS plugin to add colors from a JSON file

Usage no npm install needed!

<script type="module">
  import postcssColorsJson from 'https://cdn.skypack.dev/postcss-colors-json';
</script>

README

PostCSS Colors JSON

PostCSS plugin to add colors from a JSON file.

colors.json:

{
  accentColor: "#8093F1"
}

input:

.foo {
    color: --accentColor
}

output:

.foo {
  color: #8093F1
}

Usage

Step 1: Install plugin:

yarn add -D postcss postcss-colors-json

or

npm install --save-dev postcss postcss-colors-json

Step 2: Check you project for existed PostCSS config: postcss.config.js in the project root, "postcss" section in package.json or postcss in bundle config.

If you do not use PostCSS, add it according to official docs and set this plugin in settings.

Step 3: Add the plugin to plugins list:

module.exports = {
  plugins: [
+   require('postcss-colors-json')({
+     json: 'src/colors/colors.json',
+     prefix: '--',
+   }),
    require('autoprefixer')
  ]
}

Defaults options

{
  json: 'colors.json',
  prefix: '--',
}

prefix: Prefix for the color name variable. Default value is --. Can be $, @.

json:: Path to the colors json file. Starts from the project root directory. Default value is: colors.json