第一步
npm install postcss-px2rem -S
npm install px2rem-loader -S
第二步
- src->utils 目录下创建
rem
文件,文件内容如下:
const baseSize = 16
function setRem() {
const scale = document.documentElement.clientWidth / 1920
document.documentElement.style.fontSize = baseSize * Math.min(scale, 2) + 'px'
}
setRem()
window.onresize = function () {
setRem()
}
第三步
import './utils/rem'
第四步
const postcss = px2rem({
remUnit: 16
})
css: {
loaderOptions: {
sass: {
sassOptions: { outputStyle: "expanded" }
}
}
postcss: {
plugins: [
postcss
]
}
},