Transforming css from px to rem, base on pxrem
- Test coverage
- Examples
- 中文文档
- Publish to npm
$ npm i -D cupools/fis3-postprocessor-pxrem
fis.match('*.css', {
postprocessor: fis.plugin('pxrem', {
root: 75,
filter: /^border/,
fixed: 6,
keepPx: false,
commentFilter: 'no'
})
})
- root: root value from px to rem, default to 75
- filter: css declaration that should be ignored, can be regexp or function, default to null
- fixed: precision of rem value, default to 6
- keepPx: keep px for compatible in old browsers, default to false
- commentFilter: comment after css declaration that should be ignored, default to 'no'
fis.match('*.css', {
postprocessor: fis.plugin('pxrem', {
root: 75,
filter: /^border/,
fixed: 6,
keepPx: false,
commentFilter: 'no'
})
})
/* before */
.foo {
margin: 15px auto;
width: 15px;
height: 75px;
font-size: 24px; /*no*/
border: 1px solid #000;
}
/* after */
.foo {
margin: 0.2rem auto;
width: 0.2rem;
height: 1rem;
font-size: 24px;
border: 1px solid #000;
}
fis.match('*.css', {
postprocessor: fis.plugin('pxrem', {
root: 75,
filter: function(prop, val, decl) {
return prop === 'border' && val === '1px'
}
})
})
/* before */
.foo {
margin: 15px auto;
width: 15px;
height: 75px;
font-size: 24px; /*no*/
border: 1px solid #000;
}
/* after */
.foo {
margin: 0.2rem auto;
width: 0.2rem;
height: 1rem;
font-size: 24px;
border: 1px solid #000;
}
fis.match('*.css', {
postprocessor: fis.plugin('pxrem', {
root: 75,
filter: /^border/,
keepPx: true
})
})
/* before */
.foo {
margin: 15px auto;
width: 15px;
height: 75px;
font-size: 24px; /*no*/
border: 1px solid #000;
}
/* after */
.foo {
margin: 15px auto;
margin: 0.2rem auto;
width: 15px;
width: 0.2rem;
height: 75px;
height: 1rem;
font-size: 24px;
border: 1px solid #000;
}