diff --git a/README.md b/README.md index b013a20..c7765f3 100644 --- a/README.md +++ b/README.md @@ -211,7 +211,7 @@ template is rendered. This variable has the following attributes: Filtering chunks ---------------- -To include only certain chunks you can limit the chunks beeing used: +To include only certain chunks you can limit the chunks being used: ```javascript plugins: [ diff --git a/index.js b/index.js index e552ec5..e9245da 100644 --- a/index.js +++ b/index.js @@ -72,6 +72,7 @@ HtmlWebpackPlugin.prototype.emitHtml = function(compilation, htmlTemplateContent HtmlWebpackPlugin.prototype.htmlWebpackPluginAssets = function(compilation, webpackStatsJson, includedChunks, excludedChunks) { + var self = this; var publicPath = compilation.options.output.publicPath || ''; var assets = { @@ -87,6 +88,11 @@ HtmlWebpackPlugin.prototype.htmlWebpackPluginAssets = function(compilation, webp })[0] }; + // Append a hash for cache busting + if (this.options.hash) { + assets.manifest = self.appendHash(assets.manifest, webpackStatsJson.hash); + } + var chunks = webpackStatsJson.chunks.sort(function orderEntryLast(a, b) { if (a.entry !== b.entry) { return b.entry ? 1 : -1; @@ -118,7 +124,7 @@ HtmlWebpackPlugin.prototype.htmlWebpackPluginAssets = function(compilation, webp // Append a hash for cache busting if (this.options.hash) { chunkFiles = chunkFiles.map(function(chunkFile) { - return chunkFile + (chunkFile.indexOf('?') === -1 ? '?' : '&') + webpackStatsJson.hash; + return self.appendHash(chunkFile, webpackStatsJson.hash); }); } @@ -200,6 +206,15 @@ HtmlWebpackPlugin.prototype.htmlWebpackPluginLegacyAssets = function(compilation return legacyAssets; }; +/** + * Appends a cache busting hash + */ +HtmlWebpackPlugin.prototype.appendHash = function (url, hash) { + if (!url) { + return url; + } + return url + (url.indexOf('?') === -1 ? '?' : '&') + hash; +}; module.exports = HtmlWebpackPlugin;