This is a postcss plugin for translating dpr(...)
, rem(...)
, url(...)
. Similar to px2rem, but using custom function istead of comments for syntax.
module.exports = {
module: {
loaders: [
{
test: /\.css$/,
loader: "style-loader!css-loader!postcss-loader"
}
]
},
postcss: function() {
// remUnit defaults to 75
return [require('postcss-flexible')({remUnit: 75})]
}
}
Before processing:
.selector {
font-size: dpr(32px);
width: rem(75px);
line-height: 3;
/* replace all @[1-3]x in urls: `/a/@2x/x.png`, `/a@2x/x.png` or `/a/[email protected]` */
background-image: url(/images/[email protected]);
}
After processing:
.selector {
width: 1rem;
line-height: 3;
}
[data-dpr="1"] .selector {
font-size: 16px;
background-image: url(/images/[email protected]);
}
[data-dpr="2"] .selector {
font-size: 32px;
background-image: url(/images/[email protected]);
}
[data-dpr="3"] .selector {
font-size: 48px;
background-image: url(/images/[email protected]);
}
desktop
: boolean, defaultfalse
baseDpr
: number, default2
remUnit
: number, default75
remPrecision
: number, default6
addPrefixToSelector
: functiondprList
: array, default[3, 2, 1]
fontGear
: array, default[-1, 0, 1, 2, 3, 4]
enableFontSetting
: boolean, defaultfalse
addFontSizeToSelector
: functionoutputCSSFile
: function
- add: generate different css files with fontGear
- support custom
fontGear
- support custom
enableFontSetting
- support custom
addFontSizeToSelector
- support custom
outputCSSFile
- support custom
dprList
- add option
desktop
andaddPrefixToSelector
- handle
url()
- add
dpr()
andrem()
- First release.
MIT