a webpack loader for converting px
to rem
when developing repsonsive webpage
this is your css or js declaration in px
:
// css
div {
font-size: 14px;
width: 100px;
}
//js such as in react
<Page style={{ fontSize: '14px', width: '100px' }} />
after converting based on 1rem=10px
// css
div {
font-size: 1.400rem;
width: 10rem;
}
// js such as in react
<Page style={{ fontSize: '1.400rem', width: '10rem' }} />
npm install webpack-px-to-rem --save-dev
// in your webpack.config.js
module.exports={
...
module:{
// or loaders
rules:[
{
test:/\.jsx$/,
loader:'webpack-px-to-rem',
// the query is optional
query:{
// 1rem=npx default 10
basePx:10,
// only convert px greater than the given value default 0
// For the reason that tiny rem may be smaller than 1px and disappeare in tiny device
min:1,
// the rem value only has specific decimal places default 3
floatWidth:3
}
}
]
}
...
}