0.1.2 • Published 7 months ago

@tysian/postcss-custom-units v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

PostCSS Custom Units Plugin

PostCSS plugin for handling multiple custom units.

Install

Install plugin as dev dependency

npm install @tysian/postcss-custom-units --save-dev

Use your plugin in your postcss config.

import postcss from 'postcss';
import postcssCustomUnits from '@tysian/postcss-custom-units';

const pluginOptions = {
  units: [
    {
      base: '0.0625rem',
      unit: 'rpx',
    },
  ],
};

postcss([postcssCustomUnits(pluginOptions)]).process(
  YOUR_CSS /*, processOptions */,
);

Configuration

The custom units are defined inside your plugin config. You CAN'T define or update them using css variables. In plugin options, pass units as array, with custom units. Custom unit has two properties:

  • base - your X unit will be transformed into X * base Example: if base = 4px, then 5unit = 20px
  • unit - the name of your unit

Here is an example with 1rpx, where 1rpx = 1px but it is transformed into rem.

const pluginOptions = {
  units: [
    {
      base: '0.0625rem',
      unit: 'rpx',
    },
  ],
};

Credits

Project based on:

License

MIT License © 2023-PRESENT Jakub Bazgier

0.1.2

7 months ago

0.1.1

7 months ago