postcss-2rem-2vw
v1.0.6
Published
Convert px to rem or vw
Downloads
3
Readme
postcss-2rem-2vw
用于转换 px 单位至 rem 和 vw 单位。
install
npm i postcss-2rem-2vw
Options
baseSize
: 转换基准,默认{ rem: 75, vw: 7.5 }
,如原始大小为36px
,则转换后为0.48rem
和4.8vw
。precision
: 默认6
,转换保留有效位数。forceRemProps
: 只生成rem
单位,不生成vw
单位的属性。keepRuleComment
: 默认'no'
,不转换的行注释。keepFileComment
: 默认'px2rem2vw-disable'
,不转换的文件注释。toRem
: 默认true
,是否生成rem
单位。toVw
: 默认true
,是否生成vw
单位。
Usage
Postcss
import postcss from "postcss";
import pxToRemVw from "postcss-2rem-2vw";
const opts = {};
postcss([pxToRemVw(opts)])
.process(css, { from: "./input.css", to: "./output.css" })
.then(result => {
fs.writeFileSync("./output.css", result.css);
if (result.map) fs.writeFile("./output.css.map", result.map);
})
.catch(err => {
console.error(err);
});
postcss-loader
{
test: /.css$/,
loader: {
loader: require.resolve('postcss-loader'),
options: {
// ...
plugins: () => [
// ...
require('postcss-2rem-2vw')({
baseSize: {
rem: 750,
vw: 7.5
},
precision: 6,
forceRemProps: [ 'font', 'font-size' ],
keepRuleComment: 'no',
keepFileComment: 'px2rem2vw-disable',
toVw: shouldPostCssGenVw,
toRem: shouldPostCssGenRem
}),
],
// ...
},
}
}