Skip to content

Instantly share code, notes, and snippets.

@Uzwername
Last active August 23, 2020 19:06
Show Gist options
  • Save Uzwername/34d4d85cb308560d85876f7dd4d8717a to your computer and use it in GitHub Desktop.
Save Uzwername/34d4d85cb308560d85876f7dd4d8717a to your computer and use it in GitHub Desktop.
HtmlWebpackPlugin - config step 2
<script>
(function() {
function showErrorMessage() {
alert('Oops, something went wrong! Please reload the page.');
}
// Paths of all bundles
var bundlesSrcs = <%= JSON.stringify(htmlWebpackPlugin.files.js) %>;
for(var i=0; i < bundlesSrcs.length; i++) {
// Create script tag & configure it
var scriptTag = document.createElement('script');
scriptTag.src = bundlesSrcs[i];
scriptTag.addEventListener('error', showErrorMessage);
// Append script tag into body
document.body.appendChild(scriptTag);
}
})();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment