postcss-custom-props

A PostCSS plugin to enable CSS Custom Properties

Usage no npm install needed!

<script type="module">
  import postcssCustomProps from 'https://cdn.skypack.dev/postcss-custom-props';
</script>

README

PostCSS custom props

A PostCSS plugin to enable CSS Custom Properties (CSS variables).

Features

Limitations

This will only work as the spec sets out if you define your custom properties on :root. See the following discussions on pre-processing CSS properties from the postcss-custom-properties plugin repository:

Installation

npm install postcss-custom-props

Usage

Webpack

...
import atImport from 'postcss-import';
import colorFunction from 'postcss-color-function';
import customProps from 'postcss-custom-props';

export default {
  ...
  postcss: [
    atImport(),
    customProps(),
    colorFunction(),
  ],
};

Input

/* config.css */
:root {
  --brand-color: #f05;
}

/* component.css */
@import "./config.css";

:root {
  --compoment-bg-color: var( --brand-color );
  --component-font-color: color( var( --brand-color ) lighten( 30% ));
}

.component {
  background-color: var( --compoment-bg-color );
  color: var( --component-font-color );
}

Output

.component {
  background-color: #f05;
  color: #fcd;
}