Skip to content
Advertisement

HtmlWebpackPlugin: wrong hash for script file is injected into html file

I’m trying to use HtmlWebpackPlugin to generate .HTML file

when running build with webpack i get this issue where the src of script tag in HTML file is not same as the script file name

here is my webpack config:

JavaScript

this is the generated HTML:

JavaScript

and here is my dist folder:

dist-folder

as you can see the name of bundle file is okay, but the script tag at the and of the body has wrong src

Advertisement

Answer

I found a solution to this in the comments of this Github issue: https://github.com/jantimon/html-webpack-plugin/issues/1638

In the optimization section of your webpack config file, set realContentHash to false:

JavaScript

So for example my webpack configuration object looks like this:

JavaScript

This can sometimes produce the suboptimal situation where hashes change more than is necessary, but it seems to be the best solution for now (pending updates to the issue.)

Advertisement