-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Uses a singleton cache to store the compilation stats #723
Changes from 2 commits
b8454b4
842c49e
4f2e6d0
2651b28
bcc0722
bfd6f5b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,16 @@ var prettyError = require('./lib/errors.js'); | |
var chunkSorter = require('./lib/chunksorter.js'); | ||
Promise.promisifyAll(fs); | ||
|
||
var getStats = (function () { | ||
var cachedStats = {}; | ||
|
||
return function (compilation) { | ||
var hash = compilation.hash; | ||
cachedStats[hash] = cachedStats[hash] || compilation.getStats().toJson(); | ||
return cachedStats[hash]; | ||
}; | ||
}()); | ||
|
||
function HtmlWebpackPlugin (options) { | ||
// Default options | ||
this.options = _.extend({ | ||
|
@@ -65,7 +75,7 @@ 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; | ||
var allChunks = getStats(compilation).chunks; | ||
// Filter chunks (options.chunks and options.excludeCHunks) | ||
var chunks = self.filterChunks(allChunks, self.options.chunks, self.options.excludeChunks); | ||
// Sort chunks | ||
|
@@ -252,7 +262,7 @@ HtmlWebpackPlugin.prototype.executeTemplate = function (templateFunction, chunks | |
.then(function () { | ||
var templateParams = { | ||
compilation: compilation, | ||
webpack: compilation.getStats().toJson(), | ||
webpack: getStats(compilation), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is equivalent to just passing I believe, the only difference between Not 100% sure on this one thought There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From the doc, this should be
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep you are right 👍 |
||
webpackConfig: compilation.options, | ||
htmlWebpackPlugin: { | ||
files: assets, | ||
|
@@ -384,7 +394,7 @@ HtmlWebpackPlugin.prototype.isHotUpdateCompilation = function (assets) { | |
|
||
HtmlWebpackPlugin.prototype.htmlWebpackPluginAssets = function (compilation, chunks) { | ||
var self = this; | ||
var webpackStatsJson = compilation.getStats().toJson(); | ||
var webpackStatsJson = getStats(compilation); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. only needed to get the hash, which we can get by doing |
||
|
||
// Use the configured public path or build a relative path | ||
var publicPath = typeof compilation.options.output.publicPath !== 'undefined' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be replaced by
compilation.chunks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing this will change the api of
chunksSortMode
. Before it received two objects with an array propertynames
. Now they will have a string propertyname
. Example:Is not documented in the docs (https://github.com/jantimon/html-webpack-plugin#writing-your-own-templates), but it could break some uses. Are you ok with this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah probably not :D
I was wrong here. So is everything still works with
getStats()
then without the need fortoJSON()
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually a few properties will change:
Before
After