auto-px2rem-loader
a webpack loader to process css file which can convert
px
uint torem
andmedia query
code
Before processing:
The raw stylesheet:
After processing:
Rem and Media Query version:
{} {} {}
Install
npm install auto-px2rem-loader
webpack config
moduleexports = // ... module: rules: test: /\.css$/ use: loader: 'style-loader' loader: 'css-loader' loader: 'auto-px2rem-loader' // options here options: remUnit: 100 ;
All loader options
There are all default configurations in the loader, you can also customize them in the webpack config file
loader: 'auto-px2rem-loader' options: remUnit: 75 // rem unit value (default: 75) remPrecision: 6 // rem value precision (default: 6) forcePxComment: 'px' // force px comment (default: `px`) forceRemComment: 'rem' // force rem comment (default: `rem`) keepComment: 'no' // no conversion comment (default: `no`) // comment has higher priority than autodeal css properties // these css properties will be converted into media query, fauzzy matching autoDealPx: 'font-size' // these css properties will not be converted, fauzzy matching autoDealNo: 'border' 'shadow' 'min' 'max' appendAutoDealPx: // this will merge to autoDealPx, fauzzy matching appendAutoDealNo: // this will merge to autoDealNo, fauzzy matching mediaQuery: // media query rules mediaType: '(max-width: 1280px)' // media query width ratio: 05 // conversion ratio mediaType: '(min-width: 1281px) and (max-width: 1920px)' ratio: 1 mediaType: '(min-width: 1921px)' ratio: 15