在這里首先要說明下rem是什么?
rem是相對於根元素的字體大小的單位
px2rem安裝
yarn add px2rem
- 1
在utils中增加px2remLoader 
看看里面的配置項option是些什么吧
Usage: px2rem [options] <file...> Options: -h, --help output usage information -V, --version output the version number -u, --remUnit [value] set `rem` unit value (default: 75) // 是否生成不同dpr對應的樣式 -x, --threeVersion [value] whether to generate @1x, @2x and @3x version stylesheet (default: false) // 是否生成rem樣式表 -r, --remVersion [value] whether to generate rem version stylesheet (default: true) // 默認dpr -b, --baseDpr [value] set base device pixel ratio (default: 2) // px轉rem的精度 -p, --remPrecision [value] set rem value precision (default: 6) -o, --output [path] the output file dirname
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
說下這個remUnit是個什么呢?就是1rem等於多少px的轉換單位,默認是75,我建議在750的設計稿時設置為750,為什么?因為我只需要將RootFontSize設置為瀏覽器寬度就行了 
然后在寫樣式時,設計圖書是多少px就是多少px
對應的效果
默認是將所有的px轉換為rem,對於那些不需要轉換的如1px border
The raw stylesheet only contains @2x style, and if you
don’t intend to transform the original value, eg: 1px border, add /no/ after the declaration
intend to use px by force,eg: font-size, add /px/ after the declaration
就是說這樣做是不會轉rem的
border: 1px;/*no*/ font-size: 20px;/*px*/
- 1
- 2
- 注意:對於習慣用stylus的去掉樣式結尾封號的,在這里不能省略 ‘;’
