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

今天在开发的时候,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.

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
`mini-css-extract-plugin` 是一个 Webpack 插件,用于从 JavaScript bundle 中提取 CSS 到单独的文件中。与使用 `style-loader` 将 CSS 插入 `<style>` 标签不同,`mini-css-extract-plugin` 可以帮助您创建一个单独的 CSS 文件,该文件可以在浏览器中缓存,从而提高网站的性能和加载速度。 使用 `mini-css-extract-plugin` 非常简单。首先,您需要在 Webpack 配置文件中安装和导入插件: ```javascript const MiniCssExtractPlugin = require('mini-css-extract-plugin'); ``` 然后,您需要在插件配置中指定输出文件的名称和路径: ```javascript plugins: [ new MiniCssExtractPlugin({ filename: 'css/[name].[contenthash].css', }), ], ``` 在上面的代码中,`filename` 选项指定输出文件的名称和路径。`[name]` 会被替换为入口名称,`[contenthash]` 会被替换为根据文件内容生成的哈希值,这样可以确保每次构建生成的文件都有一个唯一的文件名。 最后,您需要在 Webpack 配置文件的加载器中使用 `mini-css-extract-plugin`,以便在构建期间从 JavaScript bundle 中提取 CSS: ```javascript module: { rules: [ { test: /\.css$/, use: [MiniCssExtractPlugin.loader, 'css-loader'], }, ], }, ``` 在上面的代码中,`MiniCssExtractPlugin.loader` 用于从 JavaScript bundle 中提取 CSS,`css-loader` 用于将 CSS 转换为 JavaScript 可以理解的模块格式。这些加载器可以根据您的需要进行修改,以便处理不同类型的 CSS。 以上是使用 `mini-css-extract-plugin` 的基本步骤。使用此插件可以帮助您提高网站的性能和加载速度,特别是对于大型网站和长时间运行的应用程序。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值