我使用create-react-app创建的工程,然后使用config-override.js复写配置。其中,使用到了postcss-pxtorem
const { override, addPostcssPlugins} = require("customize-cra");
const path = require("path");
module.exports = {
webpack: override(
addPostcssPlugins([require('postcss-pxtorem')({
rootValue: 100,
propList: ['*'],
exclude: /node_modules/i
})])
)
}
同时在index.html文件中添加了:
(function () {
var initFontSize = 16
var iPhone6Width = 375
var clientWidth = window.document.documentElement.clientWidth || iPhone6Width
var newFontSize = initFontSize * (clientWidth / iPhone6Width)
document.documentElement.style.fontSize = newFontSize + 'px'
})()
然后我写了一个div,宽度为100px。
在浏览器调试模式中发现100px并没有转化为1rem,请问是哪里出了问题呢?