webpack-px-to-rem
Version:
convert your px attribute to rem
71 lines (63 loc) • 1.65 kB
Markdown
[](https://badge.fury.io/js/webpack-px-to-rem)
a webpack loader for converting `px` to `rem` when developing repsonsive webpage
- [Introduction](
- [Installation](
- [Usage](
this is your css or js declaration in `px`:
```css
// css
div {
font-size: 14px;
width: 100px;
}
```
```javascript
//js such as in react
<Page style={{ fontSize: '14px', width: '100px' }} />
```
after converting based on `1rem=10px`
```css
// css
div {
font-size: 1.400rem;
width: 10rem;
}
```
```javascript
// js such as in react
<Page style={{ fontSize: '1.400rem', width: '10rem' }} />
```
```javascript
npm install webpack-px-to-rem --save-dev
```
```javascript
// 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
}
}
]
}
...
}
```