Skip to content

Commit d48ec1e

Browse files
authored
fix(resource-hints): exclude hot-update files in dev mode (#6347)
1 parent eeebfe5 commit d48ec1e

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

packages/core/src/plugins/resourceHints.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export const pluginResourceHints = (): RsbuildPlugin => ({
6161
return { headTags, bodyTags };
6262
});
6363

64-
api.modifyBundlerChain((chain, { CHAIN_ID, environment }) => {
64+
api.modifyBundlerChain((chain, { CHAIN_ID, environment, isDev }) => {
6565
const { config, htmlPaths } = environment;
6666

6767
if (Object.keys(htmlPaths).length === 0) {
@@ -85,7 +85,12 @@ export const pluginResourceHints = (): RsbuildPlugin => ({
8585

8686
chain
8787
.plugin(CHAIN_ID.PLUGIN.HTML_PREFETCH)
88-
.use(HtmlResourceHintsPlugin, [options, 'prefetch', HTMLCount]);
88+
.use(HtmlResourceHintsPlugin, [
89+
options,
90+
'prefetch',
91+
HTMLCount,
92+
isDev,
93+
]);
8994
}
9095

9196
if (preload) {
@@ -99,7 +104,7 @@ export const pluginResourceHints = (): RsbuildPlugin => ({
99104

100105
chain
101106
.plugin(CHAIN_ID.PLUGIN.HTML_PRELOAD)
102-
.use(HtmlResourceHintsPlugin, [options, 'preload', HTMLCount]);
107+
.use(HtmlResourceHintsPlugin, [options, 'preload', HTMLCount, isDev]);
103108
}
104109
});
105110
},

packages/core/src/rspack-plugins/resource-hints/HtmlResourceHintsPlugin.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ function generateLinks(
135135
compilation: Compilation,
136136
data: HtmlRspackPlugin.BeforeAssetTagGenerationData,
137137
HTMLCount: number,
138+
isDev: boolean,
138139
): HtmlRspackPlugin.HtmlTagObject[] {
139140
// get all chunks
140141
const extractedChunks = extractChunks(compilation, options.type);
@@ -164,8 +165,13 @@ function generateLinks(
164165
]),
165166
[],
166167
)
167-
// source map files should always be excluded
168-
.filter((file) => !file.endsWith('.map'));
168+
// source map and hot-update files should always be excluded
169+
.filter((file) => {
170+
if (isDev && file.endsWith('.hot-update.js')) {
171+
return false;
172+
}
173+
return !file.endsWith('.map');
174+
});
169175

170176
const uniqueFiles = new Set<string>(allFiles);
171177
const filteredFiles = applyFilter(
@@ -234,14 +240,18 @@ export class HtmlResourceHintsPlugin implements RspackPluginInstance {
234240

235241
HTMLCount: number;
236242

243+
isDev: boolean;
244+
237245
constructor(
238246
options: ResourceHintsOptions,
239247
type: LinkType,
240248
HTMLCount: number,
249+
isDev: boolean,
241250
) {
242251
this.options = { ...defaultOptions, ...options };
243252
this.type = type;
244253
this.HTMLCount = HTMLCount;
254+
this.isDev = isDev;
245255
}
246256

247257
apply(compiler: Compiler): void {
@@ -256,6 +266,7 @@ export class HtmlResourceHintsPlugin implements RspackPluginInstance {
256266
compilation,
257267
data,
258268
this.HTMLCount,
269+
this.isDev,
259270
);
260271

261272
return data;

0 commit comments

Comments
 (0)