首先以下方法只能在微信小程序中生效,在h5端並不生效,其他小程序還沒有測
安裝依賴
npm install postcss-px-scale -dev
安裝完之后在根目錄config文件夾的index文件中找到以下字段並修改
designWidth: 375, deviceRatio: { 640: 2.34 / 2, 750: 1, 828: 1.81 / 2, 375:1/2 },
然后在當前文件中mini項中的 postcss 加入就可以了
"postcss-px-scale": { "enable": true, "config": { "scale": 0.5, //縮放為1/2 "units": "rpx", "includes": ["taro-ui"] } },
但也有的說在h5配置項中的 postcss 加入
"postcss-px-scale": { "enable": true, "config": { "scale": 0.5, //縮放為1/2 "units": "rem", "includes": ["taro-ui"] } },
在indexjs文件的h5中加入當前字段
esnextModules: ['taro-ui'],
重新打包,會在h5頁面看到字體大小正常