Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce stats requested at emit and optionally remove from template #825

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ function HtmlWebpackPlugin (options) {
chunks: 'all',
excludeChunks: [],
title: 'Webpack App',
xhtml: false
xhtml: false,
templateStats: true
}, options);
}

Expand Down Expand Up @@ -64,8 +65,24 @@ HtmlWebpackPlugin.prototype.apply = function (compiler) {

compiler.plugin('emit', function (compilation, callback) {
var applyPluginsAsyncWaterfall = self.applyPluginsAsyncWaterfall(compilation);
// Get all chunks
var allChunks = compilation.getStats().toJson().chunks;
// Get chunks info as json
// Note: we're excluding stuff that we don't need to improve toJson serialization speed.
var chunkOnlyConfig = {
assets: false,
cached: false,
children: false,
chunks: true,
chunkModules: false,
chunkOrigins: false,
errorDetails: false,
hash: false,
modules: false,
reasons: false,
source: false,
timings: false,
version: false
};
Copy link

@n0v1 n0v1 May 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be simplified according to the docs:

var chunkOnlyConfig = {
  all: false,
  chunks: true
};

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool good point! 👍
We will remove the getStats call in #953

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even better 👍. Thanks for your work!

var allChunks = compilation.getStats().toJson(chunkOnlyConfig).chunks;
// Filter chunks (options.chunks and options.excludeCHunks)
var chunks = self.filterChunks(allChunks, self.options.chunks, self.options.excludeChunks);
// Sort chunks
Expand Down Expand Up @@ -252,7 +269,7 @@ HtmlWebpackPlugin.prototype.executeTemplate = function (templateFunction, chunks
.then(function () {
var templateParams = {
compilation: compilation,
webpack: compilation.getStats().toJson(),
webpack: self.options.templateStats ? compilation.getStats().toJson() : undefined,
webpackConfig: compilation.options,
htmlWebpackPlugin: {
files: assets,
Expand Down