Skip to content

Commit

Permalink
fix: prevent scripts marked as hotModuleReplacement from being added …
Browse files Browse the repository at this point in the history
…to the html file
  • Loading branch information
jantimon committed Apr 28, 2020
1 parent ceafe14 commit 119252a
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion index.js
Expand Up @@ -574,7 +574,21 @@ class HtmlWebpackPlugin {
const extensionRegexp = /\.(css|js|mjs)(\?|$)/;
for (let i = 0; i < entryNames.length; i++) {
const entryName = entryNames[i];
const entryPointFiles = compilation.entrypoints.get(entryName).getFiles();
/** entryPointUnfilteredFiles - also includes hot module update files */
const entryPointUnfilteredFiles = compilation.entrypoints.get(entryName).getFiles();

const entryPointFiles = entryPointUnfilteredFiles.filter((chunkFile) => {
// compilation.getAsset was introduced in webpack 4.4.0
// once the support pre webpack 4.4.0 is dropped please
// remove the following guard:
if (!compilation.getAsset) {
return true;
}
// Prevent hot-module files from beeing included:
const assetMetaInformation = compilation.getAsset(chunkFile).info || {};
return !(assetMetaInformation.hotModuleReplacement || assetMetaInformation.development);
});

// Prepend the publicPath and append the hash depending on the
// webpack.output.publicPath and hashOptions
// E.g. bundle.js -> /bundle.js?hash
Expand Down

0 comments on commit 119252a

Please sign in to comment.