Skip to content

Commit

Permalink
Minor refactoring because of #179
Browse files Browse the repository at this point in the history
Release 2.6.5
  • Loading branch information
jantimon authored and Jan Nicklas committed Jan 19, 2016
1 parent c4ee173 commit d5c4e08
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 27 deletions.
40 changes: 14 additions & 26 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,20 @@ HtmlWebpackPlugin.prototype.apply = function(compiler) {

compiler.plugin('make', function(compilation, callback) {
// Compile the template (queued)
compilationPromise = getNextCompilationSlot(compiler, function() {
return childCompiler.compileTemplate(self.options.template, compiler.context, self.options.filename, compilation)
.catch(function(err) {
compilation.errors.push(prettyError(err, compiler.context).toString());
return {
content: self.options.showErrors ? prettyError(err, compiler.context).toJsonHtml() : 'ERROR',
};
})
.then(function(compilationResult) {
// If the compilation change didnt change the cache is valid
isCompilationCached = compilationResult.hash && self.hash === compilationResult.hash;
self.hash = compilation.hash;
callback();
return compilationResult.content;
});
});
compilationPromise = childCompiler.compileTemplate(self.options.template, compiler.context, self.options.filename, compilation)
.catch(function(err) {
compilation.errors.push(prettyError(err, compiler.context).toString());
return {
content: self.options.showErrors ? prettyError(err, compiler.context).toJsonHtml() : 'ERROR'
};
})
.then(function(compilationResult) {
// If the compilation change didnt change the cache is valid
isCompilationCached = compilationResult.hash && self.hash === compilationResult.hash;
self.hash = compilation.hash;
callback();
return compilationResult.content;
});
});

compiler.plugin('after-compile', function(compilation, callback) {
Expand Down Expand Up @@ -498,14 +496,4 @@ HtmlWebpackPlugin.prototype.getFullTemplatePath = function(template, context) {
});
};

/**
* Helper to prevent html-plugin compilation in parallel
* Fixes "No source available" where incomplete cache modules were used
*/
function getNextCompilationSlot(compiler, newEntry) {
compiler.HtmlWebpackPluginQueue = (compiler.HtmlWebpackPluginQueue || Promise.resolve())
.then(newEntry);
return compiler.HtmlWebpackPluginQueue;
}

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.6.4",
"version": "2.6.5",
"description": "Simplifies creation of HTML files to serve your webpack bundles",
"main": "index.js",
"files": [
Expand Down

0 comments on commit d5c4e08

Please sign in to comment.