postcss-plugin-px2rem
postcss plugin px2rem.
Features
A plugin for PostCSS that generates rem units from pixel units.
Installation
$ npm i --save postcss-plugin-px2rem
Usage
input and output
// //
original
;;; const css = ;const options = replace: false;const processedCss = css; ;
with webpack
;const px2remOpts = ......; module: loaders: test: /\.css$/ loader: 'style-loader!css-loader!postcss-loader' postcss:
atool-build
withwebpack.connfig.js
;; const px2remOpts = ...... ; webpackConfigpostcss; return webpackConfig;;
Configuration
Default:
rootValue: 100 unitPrecision: 5 propWhiteList: propBlackList: exclude:false selectorBlackList: ignoreIdentifier: false replace: true mediaQuery: false minPixelValue: 0
rootValue
(Number|Object) The root element font size. Default is 100.- If rootValue is an object, for example
{ px: 50, rpx: 100 }
, it will replace rpx to 1/100 rem , and px to 1/50 rem.
- If rootValue is an object, for example
unitPrecision
(Number) The decimal numbers to allow the REM units to grow to.propWhiteList
(Array) The properties that can change from px to rem.- Default is an empty array that means disable the white list and enable all properties.
- Values need to be exact matches.
propBlackList
(Array) The properties that should not change from px to rem.- Values need to be exact matches.
exclude
(Reg) a way to exclude some folder,eg. /(node_module)/.selectorBlackList
(Array) The selectors to ignore and leave as px.- If value is string, it checks to see if selector contains the string.
['body']
will match.body-class
- If value is regexp, it checks to see if the selector matches the regexp.
[/^body$/]
will matchbody
but not.body
- If value is string, it checks to see if selector contains the string.
ignoreIdentifier
(Boolean/String) a way to have a single property ignored, when ignoreIdentifier enabled, thenreplace
would be set totrue
automatically.replace
(Boolean) replaces rules containing rems instead of adding fallbacks.mediaQuery
(Boolean) Allow px to be converted in media queries.minPixelValue
(Number) Set the minimum pixel value to replace.
License
MIT