Minor refactoring because of #179

Release 2.6.5
This commit is contained in:
Jan Nicklas 2016-01-19 14:52:25 +01:00 committed by Jan Nicklas
parent c4ee1738e7
commit d5c4e08457
2 changed files with 15 additions and 27 deletions

View File

@ -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) {
@ -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;

View File

@ -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": [