1 安装postcss-plugin-px2rem
npm i postcss-plugin-px2rem --save-dev
2 webpack配置postcss-loader
const px2rem = require("postcss-plugin-px2rem");
const px2remOpts = {
rootValue: 100,
exclude: /(node_module)/,
mediaQuery: false,
minPixelValue: 3,
};
.......
{
loader: require.resolve("postcss-loader"),
options: {
ident: "postcss",
plugins: () => [
require("postcss-flexbugs-fixes"),
require("postcss-preset-env")({
autoprefixer: {
flexbox: "no-2009",
},
stage: 3,
}),
px2rem(px2remOpts),
postcssNormalize(),
],
sourceMap: isEnvProduction ? shouldUseSourceMap : isEnvDevelopment,
},
},
postcss-