Skip to content

Commit

Permalink
v2.8.1: Improve caching - fixes #204
Browse files Browse the repository at this point in the history
  • Loading branch information
jantimon authored and Jan Nicklas committed Feb 3, 2016
1 parent 3f38901 commit 99a8d7e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
29 changes: 20 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,13 @@ HtmlWebpackPlugin.prototype.apply = function (compiler) {
})
.then(function (compilationResult) {
// If the compilation change didnt change the cache is valid
isCompilationCached = compilationResult.hash && self.hash === compilationResult.hash;
self.hash = compilation.hash;
isCompilationCached = compilationResult.hash && self.childCompilerHash === compilationResult.hash;
self.childCompilerHash = compilationResult.hash;
callback();
return compilationResult.content;
});
});

compiler.plugin('after-compile', function (compilation, callback) {
// Clear the compilation queue
delete compiler.HtmlWebpackPluginQueue;
callback();
});

compiler.plugin('emit', function (compilation, callback) {
var applyPluginsAsyncWaterfall = Promise.promisify(compilation.applyPluginsAsyncWaterfall, {context: compilation});
// Get all chunks
Expand All @@ -68,7 +62,7 @@ HtmlWebpackPlugin.prototype.apply = function (compiler) {
var assets = self.htmlWebpackPluginAssets(compilation, chunks);

// If the template and the assets did not change we don't have to emit the html
var assetJson = JSON.stringify(assets);
var assetJson = JSON.stringify(self.getAssetFiles(assets));
if (isCompilationCached && self.options.cache && assetJson === self.assetJson) {
return callback();
} else {
Expand Down Expand Up @@ -484,6 +478,9 @@ HtmlWebpackPlugin.prototype.appendHash = function (url, hash) {
return url + (url.indexOf('?') === -1 ? '?' : '&') + hash;
};

/**
* Helper to return the absolute template path with a fallback loader
*/
HtmlWebpackPlugin.prototype.getFullTemplatePath = function (template, context) {
// If the template doesn't use a loader use the lodash template loader
if (template.indexOf('!') === -1) {
Expand All @@ -497,4 +494,18 @@ HtmlWebpackPlugin.prototype.getFullTemplatePath = function (template, context) {
});
};

/**
* Helper to return a sorted unique array of all asset files out of the
* asset object
*/
HtmlWebpackPlugin.prototype.getAssetFiles = function (assets) {
var files = _.uniq(Object.keys(assets).filter(function (assetType) {
return assetType !== 'chunks' && assets[assetType];
}).reduce(function (files, assetType) {
return files.concat(assets[assetType]);
}, []));
files.sort();
return files;
};

module.exports = HtmlWebpackPlugin;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "html-webpack-plugin",
"version": "2.8.0",
"version": "2.8.1",
"description": "Simplifies creation of HTML files to serve your webpack bundles",
"main": "index.js",
"files": [
Expand Down

0 comments on commit 99a8d7e

Please sign in to comment.