-
Notifications
You must be signed in to change notification settings - Fork 2.7k
less代码打包后组件样式错误覆盖 #4978
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
+1 |
+1 |
1 similar comment
+1 |
研究了下,参考官网提示,摸索了有个效的解决方案,希望也对遇到相同问题的大家有帮助。 配置里增加splitChunks chainWebpack(config) {
config.optimization.splitChunks({
cacheGroups: {
common: {
name: 'common',
test: /\.(css|less)$/,
chunks: 'async',
minChunks: 1,
minSize: 0,
priority: 10,
reuseExistingChunk: true,
},
antdVendor: {
test: /[\\/]node_modules[\\/](antd)[\\/]/,
name: "antdVendor",
priority: 20,
},
},
});
}, |
+1 |
我排查下 |
后来解决了吗?我遇到了同样的问题,这是我的路由配置: routes: [
{
path: '/',
component: '../layouts/index',
routes: [
{ path: '/', component: '../pages/index' },
{ path: '/article', component: '../pages/Article'},
{ path: '/girl', component: '../pages/Girl'},
{ path: '/cp', component: '../pages/Cp'},
]
}
],
.filters .btn {
border-color: transparent;
font-size: .8rem;
padding: 8px 15px;
margin: 3px;
background: rgba(52, 58, 64, 0.05) !important;
color: #343a40 !important;
} |
这个问题目前有解决方案吗?我是按需加载的时候,antd 样式会被重复打包一遍,并且和组件的样式在同一个 css 文件,刚好这部分被重复打包的样式就在组件样式的后面,所以就被覆盖了 |
还需要添加配置 chunks: ['antdVendor', 'common', 'umi'] |
What happens?
比如有A、B两个页面,都引用了组件C,A、B都写了自己的样式去覆盖C组件中的样式,最终打包出来的结果是A.css、B.css中都有C组件的样式。因为C组件的样式定义在最前面,可以被A、B组件的样式正确覆盖,所以单独加载A、B页面都没问题。但是从A切到B,再切回A,就会发现A的样式被B中的C组件样式覆盖了。因为从A切到B的时候,B.css会加到标签中,因为B.css在A.css后面,所以B.css中的C组件样式优先级高于A.css中的样式,这样就产生了错误覆盖。
这个bug其实之前 @youxfans 同学已经提过一个issue了,他发现less代码打包后会产生重复代码,而我发现的这个问题正是这个重复代码引起的,而且看起来挺严重的。重复代码还只是影响到文件体积,但是样式错误覆盖就影响页面渲染了,希望这个bug能尽快修复。
Mini Showcase Repository(REQUIRED)
How To Reproduce
Steps to reproduce the behavior: 1. 2.
Expected behavior 1. 2.
Context
The text was updated successfully, but these errors were encountered: