diff --git a/examples/html-loader/webpack.config.js b/examples/html-loader/webpack.config.js
index b34b7a1..d53d289 100755
--- a/examples/html-loader/webpack.config.js
+++ b/examples/html-loader/webpack.config.js
@@ -16,7 +16,12 @@ module.exports = {
},
plugins: [
new HtmlWebpackPlugin({
- filename: 'html-loader.html',
+ filename: 'index.html',
+ favicon: 'favicon.ico',
+ template: 'template.html'
+ }),
+ new HtmlWebpackPlugin({
+ filename: 'about.html',
favicon: 'favicon.ico',
template: 'template.html'
}),
diff --git a/index.js b/index.js
index 4a11cf0..dff2462 100644
--- a/index.js
+++ b/index.js
@@ -46,12 +46,20 @@ HtmlWebpackPlugin.prototype.apply = function(compiler) {
self.context = compiler.context;
compiler.plugin('make', function(compilation, callback) {
- // Compile the template
- compilationPromise = self.compileTemplate(self.options.template, self.options.filename, compilation)
- .catch(function(err) {
- return new Error(err);
- })
- .finally(callback);
+ // Compile the template (queued)
+ compilationPromise = getNextCompilationSlot(compiler, function() {
+ return self.compileTemplate(self.options.template, self.options.filename, compilation)
+ .catch(function(err) {
+ return new Error(err);
+ })
+ .finally(callback);
+ });
+ });
+
+ compiler.plugin('after-compile', function(compilation, callback) {
+ // Clear the compilation queue
+ delete compiler.HtmlWebpackPluginQueue;
+ callback();
});
compiler.plugin('emit', function(compilation, callback) {
@@ -547,5 +555,14 @@ HtmlWebpackPlugin.prototype.appendHash = function (url, hash) {
return url + (url.indexOf('?') === -1 ? '?' : '&') + hash;
};
+/**
+ * Helper to prevent compilation in parallel
+ * Fixes an issue where incomplete cache modules were used
+ */
+function getNextCompilationSlot(compiler, newEntry) {
+ compiler.HtmlWebpackPluginQueue = (compiler.HtmlWebpackPluginQueue || Promise.resolve())
+ .then(newEntry);
+ return compiler.HtmlWebpackPluginQueue;
+}
module.exports = HtmlWebpackPlugin;