create-react-app中使用postcss-pxtorem无效,请问是什么原因?

我使用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,请问是哪里出了问题呢?

阅读 2.6k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏