1.0.0 • Published 1 year ago
postcss-flexible-rpx v1.0.0
postcss-flexible-rpx
Forked from postcss-flexible
This is a postcss plugin for translatingrx, rem(...), dpr(...), url(...). Similar to px2rem, but using custom function istead of comments for syntax.
rpx is to replace the rem(...) because the rpx is more concise.
Futhermore, rx is to replace rpx for concise.
Now, also support pw and ph, translating to vw and vh
Install
npm i postcss-flexible-rpx -DUsage
Webpack
module.exports = {
module: {
loaders: [
{
test: /\.css$/,
loader: "style-loader!css-loader!postcss-loader"
}
]
},
postcss: function() {
// remUnit defaults to 75
return [require('postcss-flexible-rpx')({remUnit: 75})]
}
}Example
Before processing:
.selector {
font-size: dpr(32px);
width: 75rx;
height: rem(75px);
line-height: 3;
/* replace all @[1-3]x in urls: `/a/@2x/x.png`, `/a@2x/x.png` or `/a/x@2x.png` */
background-image: url(/images/qr@2x.png);
}After processing:
.selector {
width: 1rem;
height: 1rem;
line-height: 3;
}
[data-dpr="1"] .selector {
font-size: 16px;
background-image: url(/images/qr@1x.png);
}
[data-dpr="2"] .selector {
font-size: 32px;
background-image: url(/images/qr@2x.png);
}
[data-dpr="3"] .selector {
font-size: 48px;
background-image: url(/images/qr@3x.png);
}options
desktop: boolean, defaultfalsebaseDpr: number, default2pwUnit: number, default10phUnit: number, default10remUnit: number, default75remPrecision: number, default6addPrefixToSelector: functiondprList: array, default[3, 2, 1]fontGear: array, default[-1, 0, 1, 2, 3, 4]enableFontSetting: boolean, defaultfalseaddFontSizeToSelector: functionoutputCSSFile: function