Skip to content

Commit 119252a

Browse files
committedApr 28, 2020
fix: prevent scripts marked as hotModuleReplacement from being added to the html file
1 parent ceafe14 commit 119252a

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed
 

‎index.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,21 @@ class HtmlWebpackPlugin {
574574
const extensionRegexp = /\.(css|js|mjs)(\?|$)/;
575575
for (let i = 0; i < entryNames.length; i++) {
576576
const entryName = entryNames[i];
577-
const entryPointFiles = compilation.entrypoints.get(entryName).getFiles();
577+
/** entryPointUnfilteredFiles - also includes hot module update files */
578+
const entryPointUnfilteredFiles = compilation.entrypoints.get(entryName).getFiles();
579+
580+
const entryPointFiles = entryPointUnfilteredFiles.filter((chunkFile) => {
581+
// compilation.getAsset was introduced in webpack 4.4.0
582+
// once the support pre webpack 4.4.0 is dropped please
583+
// remove the following guard:
584+
if (!compilation.getAsset) {
585+
return true;
586+
}
587+
// Prevent hot-module files from beeing included:
588+
const assetMetaInformation = compilation.getAsset(chunkFile).info || {};
589+
return !(assetMetaInformation.hotModuleReplacement || assetMetaInformation.development);
590+
});
591+
578592
// Prepend the publicPath and append the hash depending on the
579593
// webpack.output.publicPath and hashOptions
580594
// E.g. bundle.js -> /bundle.js?hash

0 commit comments

Comments
 (0)
Please sign in to comment.