Ruoyi 框架中使用 lib-flexible 和 postcss-pxtorem 排除 treeselect 组件样式问题
在 Ruoyi 框架中,使用 lib-flexible 和 postcss-pxtorem 可以将设计稿中的 px 单位转换为 rem 单位,使得页面在不同设备上显示效果更加统一。但是,在使用 treeselect 组件时,可能会出现样式错乱的问题,因为 treeselect 组件中的样式使用了 px 单位,而 postcss-pxtorem 会将其转换为 rem 单位。
为了解决这个问题,可以在 postcss.config.js 中添加 exclude 选项,将 treeselect 组件的样式排除在转换范围之外。具体操作步骤如下:
-
打开 postcss.config.js 文件,找到 plugins 选项。
-
在 plugins 选项中添加 postcss-pxtorem 插件,并在 options 中添加 exclude 选项,将 treeselect 组件的样式路径添加进去。
module.exports = {
plugins: {
'postcss-import': {},
'postcss-url': {},
'postcss-preset-env': {},
'postcss-pxtorem': {
rootValue: 16,
propList: ['*'],
selectorBlackList: ['html'],
exclude: /(/|\)(treeselect)(/|\)/ // 排除 treeselect 组件样式
},
cssnano: {
preset: 'default'
}
}
}
- 保存文件并重新编译项目,treeselect 组件的样式就不会受到 postcss-pxtorem 的影响了。
注意:如果项目中还有其他使用了 px 单位的组件或样式,也需要将其添加进 exclude 选项中,以保证转换后的样式正确。
原文地址: https://www.cveoy.top/t/topic/oONB 著作权归作者所有。请勿转载和采集!