1.安装lib-flexible
yarn add lib-flexible
2.引入lib-flexible
# src/main.ts
import 'lib-flexible/flexible'
3.安装postcss-pxtorem
yarn add postcss-pxtorem
4.在根目录下新建 postcss.config.js
# project_name/postcss.config.js
module.exports = {
plugins: {
// 兼容浏览器,添加前缀
autoprefixer: {
overrideBrowserslist: [
"Android 4.1",
"iOS 7.1",
"Chrome > 31",
"ff > 31",
"ie >= 8",
"last 10 versions",
],
grid: true,
},
"postcss-pxtorem": {
//rootValue: 16,//结果为:设计稿元素尺寸/16,比如元素宽320px,最终页面会换算成 20rem
rootValue: 75, //通常结合 lib-flexible 设置 rem 基准值,默认用75,不然容易出问题
propList: ["*"], // 需要做转化处理的属性,如`hight`、`width`、`mar