Uses a singleton cache to store the compilation stats (#723)

* 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`
This commit is contained in:
Sergio Cinos 2017-07-17 15:30:18 +10:00 committed by Jan Nicklas
parent 6f15d185da
commit cb150718a3
1 changed files with 11 additions and 7 deletions

View File

@ -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,
@ -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
@ -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('/');
@ -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++) {
@ -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);
});
}