HtmlWebpackPlugin injects relative path files which breaks when loading non-root website paths

Try setting the publicPath in your webpack config:

output.publicPath="https://stackoverflow.com/"

HtmlWebpackPlugin use the publicPath to prepend the urls of the injects.

Another option is to set the base href in the <head> of your html template, to specify the base url of all relative urls in your document.

<base href="http://localhost:3000/">

Leave a Comment