Skip to content

Commit

Permalink
fix: prefetch and preload runtime generation (#1116)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait authored Nov 1, 2024
1 parent 00cdedb commit 58c6b74
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,7 @@ class MiniCssExtractPlugin {
])
: "// no hmr",
"",
withPrefetch && hasCssMatcher !== false
withPrefetch && withLoading && hasCssMatcher !== false
? `${
RuntimeGlobals.prefetchChunkHandlers
}.miniCss = ${runtimeTemplate.basicFunction("chunkId", [
Expand Down Expand Up @@ -1159,7 +1159,7 @@ class MiniCssExtractPlugin {
])};`
: "// no prefetching",
"",
withPreload && hasCssMatcher !== false
withPreload && withLoading && hasCssMatcher !== false
? `${
RuntimeGlobals.preloadChunkHandlers
}.miniCss = ${runtimeTemplate.basicFunction("chunkId", [
Expand Down
3 changes: 3 additions & 0 deletions test/cases/prefetch-preload-hmr/a.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.a {
color: red;
}
Empty file.
4 changes: 4 additions & 0 deletions test/cases/prefetch-preload-hmr/expected/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.a {
color: red;
}

3 changes: 3 additions & 0 deletions test/cases/prefetch-preload-hmr/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import "./a.css";

import(/* webpackPrefetch: true */ "./b");
21 changes: 21 additions & 0 deletions test/cases/prefetch-preload-hmr/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import webpack from "webpack";

import Self from "../../../src";

module.exports = {
entry: "./index.js",
module: {
rules: [
{
test: /\.css$/,
use: [Self.loader, "css-loader"],
},
],
},
plugins: [
new Self({
filename: "[name].css",
}),
new webpack.HotModuleReplacementPlugin(),
],
};

0 comments on commit 58c6b74

Please sign in to comment.