@tysian/postcss-custom-units
v0.1.2
Published
Custom CSS Units plugin for PostCSS
Downloads
36
Readme
PostCSS Custom Units Plugin
PostCSS plugin for handling multiple custom units.
Install
Install plugin as dev dependency
npm install @tysian/postcss-custom-units --save-devUse 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 * baseExample: ifbase=4px, then5unit=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
