Closed
Description
- Operating System: Linux
- Node Version: 14.16.0
- NPM Version: 6.14.11
- webpack Version: 5.27.2
- mini-css-extract-plugin Version: 1.3.9
Expected Behavior
Hot module reload should work with all CSS chunks.
Actual Behavior
When there are multiple CSS chunks due to optimization.splitChunks
, hot module reload only works with the last CSS chunk.
Code
https://gist.github.com/andersk/2d45d4363478b22e998e177836ebce12
// webpack.config.js
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
module.exports = {
mode: "development",
entry: {
foo: ["./common.css", "./foo.css"],
bar: ["./common.css", "./bar.css"],
},
module: {
rules: [
{ test: /\.css$/, use: [MiniCssExtractPlugin.loader, "css-loader"] },
],
},
optimization: {
splitChunks: { chunks: "all", minSize: 1 },
},
plugins: [
new HtmlWebpackPlugin({
filename: "foo.html",
template: "foo.html",
chunks: ["foo"],
}),
new HtmlWebpackPlugin({
filename: "bar.html",
template: "bar.html",
chunks: ["bar"],
}),
new MiniCssExtractPlugin(),
],
};
How Do We Reproduce?
-
git clone https://gist.github.com/andersk/2d45d4363478b22e998e177836ebce12 css-hmr-test cd css-hmr-test npm install npx webpack serve --hot
- Open http://localhost:8080/foo.html.
- Edit
foo.css
, e.g. by changinggreen
toblue
, and see that the change is applied in the browser immediately. - Edit
common.css
, e.g. by changinggreen
toblue
, and see that the change is not applied.
In the browser console, you can see that the wrong chunk has been reloaded:
[WDS] App updated. Recompiling...
[WDS] App hot update...
[HMR] Checking for updates on the server...
[HMR] Updated modules:
[HMR] - ./common.css
[HMR] App is up to date.
[HMR] css reload http://localhost:8080/foo.css
This may be the same as one of the issues reported in #444. If so, consider this to be a minimal reproducible test case as requested there.
Metadata
Metadata
Assignees
Labels
No labels