Skip to content

Latest commit

 

History

History
70 lines (63 loc) · 1.54 KB

README-en.md

File metadata and controls

70 lines (63 loc) · 1.54 KB

px2rem

npm version

a webpack loader for converting px to rem when developing repsonsive webpage

Table of Contents

Introduction

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' }} />

Installation

npm install webpack-px-to-rem --save-dev

Usage

// 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
                }
                
            }
        ]
    }
    ...
  }