先执行npm run eject 来暴露配置文件
- 需要注意的是如果run eject确保你当前项目的git没有待缓存的文件(一定要commit完
)
安装以下依赖
npm install postcss-loader --save
npm install postcss-px-to-viewport --save
在config/webpack.config.js 搜索 ‘postcss-normalize’
require('postcss-px-to-viewport')({
viewportWidth: 1920, // (Number) The width of the viewport.
unitPrecision: 3, // (Number) The decimal numbers to allow the REM units to grow to.
viewportUnit: "vw", // (String) Expected units.
selectorBlackList: [], // (Array) The selectors to ignore and leave as px.
minPixelValue: 1, // (Number) Set the minimum pixel value to replace.
mediaQuery: false // (Boolean) Allow px to be converted in media queries.
}),
本文介绍了如何通过执行`npm run eject`来暴露webpack配置,并详细讲解了安装`postcss-loader`和`postcss-px-to-viewport`插件的过程。在配置文件中,你需要找到并修改`postcss-normalize`的位置,添加转换规则,包括设置视口宽度、单位精度等参数,确保px单位在媒体查询中也能被转换。
1028

被折叠的 条评论
为什么被折叠?



