Skip to content

Commit

Permalink
Uses a singleton cache to store the compilation stats (#723)
Browse files Browse the repository at this point in the history
* Uses a singleton cache to store the compilation stats

* Use compilation.hash as the index for the cached stats

* Remove calls to compilation.getStats().toJson() because it is expensive and we actually don't need it

* Remove debugger statement

* Make changes compatible with webpack2

* Use json representation for chunks to avoid breaking `chunksSortMode`
  • Loading branch information
scinos authored and jantimon committed Jul 17, 2017
1 parent 6f15d18 commit cb15071
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ HtmlWebpackPlugin.prototype.executeTemplate = function (templateFunction, chunks
.then(function () {
var templateParams = {
compilation: compilation,
webpack: compilation.getStats().toJson(),
webpack: compilation.getStats(),
webpackConfig: compilation.options,
htmlWebpackPlugin: {
files: assets,
Expand Down Expand Up @@ -360,7 +360,11 @@ HtmlWebpackPlugin.prototype.filterChunks = function (chunks, includedChunks, exc
return false;
}
// Skip if the chunk should be lazy loaded
if (!chunk.initial) {
if (typeof chunk.isInitial === 'function') {
if (!chunk.isInitial()) {
return false;
}
} else if (!chunk.initial) {
return false;
}
// Skip if the chunks should be filtered and the given chunk was not added explicity
Expand All @@ -384,12 +388,12 @@ HtmlWebpackPlugin.prototype.isHotUpdateCompilation = function (assets) {

HtmlWebpackPlugin.prototype.htmlWebpackPluginAssets = function (compilation, chunks) {
var self = this;
var webpackStatsJson = compilation.getStats().toJson();
var compilationHash = compilation.hash;

// Use the configured public path or build a relative path
var publicPath = typeof compilation.options.output.publicPath !== 'undefined'
// If a hard coded public path exists use it
? compilation.mainTemplate.getPublicPath({hash: webpackStatsJson.hash})
? compilation.mainTemplate.getPublicPath({hash: compilationHash})
// If no public path was set get a relative url path
: path.relative(path.resolve(compilation.options.output.path, path.dirname(self.childCompilationOutputName)), compilation.options.output.path)
.split(path.sep).join('/');
Expand All @@ -415,8 +419,8 @@ HtmlWebpackPlugin.prototype.htmlWebpackPluginAssets = function (compilation, chu

// Append a hash for cache busting
if (this.options.hash) {
assets.manifest = self.appendHash(assets.manifest, webpackStatsJson.hash);
assets.favicon = self.appendHash(assets.favicon, webpackStatsJson.hash);
assets.manifest = self.appendHash(assets.manifest, compilationHash);
assets.favicon = self.appendHash(assets.favicon, compilationHash);
}

for (var i = 0; i < chunks.length; i++) {
Expand All @@ -433,7 +437,7 @@ HtmlWebpackPlugin.prototype.htmlWebpackPluginAssets = function (compilation, chu
// Append a hash for cache busting
if (this.options.hash) {
chunkFiles = chunkFiles.map(function (chunkFile) {
return self.appendHash(chunkFile, webpackStatsJson.hash);
return self.appendHash(chunkFile, compilationHash);
});
}

Expand Down

0 comments on commit cb15071

Please sign in to comment.