mini-css-extract-plugin Conflicting order 警告解决

本文详细解析了Webpack中mini-css-extract-plugin导致的CSS顺序冲突问题。通过调整JS中CSS的引入顺序,确保了一致性,消除了警告,稳定了构建过程。

今天在开发的时候,webpack提示了一个错误,mini-css-extract-plugin Conflicting order ,具体详细是提示了common.scss 和pmodal.scss两个的顺序冲突。

网上查了下,有的说是要重新安装一下mini-css-extract-plugin 升级一下版本就能解决问题。我试了下这个方法,问题没有解决。

我继续查,最后追踪到了github的下面这个issue

https://github.com/webpack-contrib/mini-css-extract-plugin/issues/250

一个官方维护人员的回复如下,简单的说,就是在js里css的引入顺序导致的问题,多个css的在js里的引入顺序不同,就会提示这个警告。例如,在1.js 里,引入的顺序是a.css, b.css; 在2.js里,引入顺序是b.css,a.css, 出现了这种引入顺序不同,就导致了警告。在两个js里把引入顺序调成一致,就没问题了。在1.js和2.js里的引入顺序都调整成a.css, b.css 就没有那个警告了。

sokra commented on 23 Aug

We are trying to generate a CSS file but your codebase has multiple possible orderings for these modules.

In this case you used table before button in one location and button before table in another location. We need to generate a single CSS file for these and can't decide which one should be first. In this case we put table before button. But this is chosen without reason. In future build we may decide the other way. But since CSS cares for rule order this can lead to issue when CSS changes without reason.

So not defining a clear order can lead to fragile builds, that's why we display a warning here.

There are two things that you can do:

Sort your imports to create a consistent order. I must admit that the warning could be improved to point to the locations that need to be changed.

Ignore the warning with stats.warningFilter when the order of these styles doesn't matter. Maybe the eventually add an option to mark order-independent styles directly.

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值