From 281566168175aed8e26a1efe0ea03be170e85263 Mon Sep 17 00:00:00 2001 From: Jan Nicklas Date: Fri, 13 Mar 2015 18:21:28 +0100 Subject: [PATCH] Allow to pass a function for custom html rendering / templating --- index.js | 3 ++- spec/HtmlWebpackPluginSpec.js | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 0f63ba3..4cda9ef 100644 --- a/index.js +++ b/index.js @@ -22,7 +22,8 @@ HtmlWebpackPlugin.prototype.apply = function(compiler) { compiler.errors.push(new Error('HtmlWebpackPlugin: cannot specify both template and templateContent options')); callback(); } else if (self.options.templateContent) { - self.emitHtml(compiler, self.options.templateContent, templateParams, outputFilename); + var templateContent = typeof self.options.templateContent === 'function' ? self.options.templateContent(templateParams, compiler) : self.options.templateContent; + self.emitHtml(compiler, templateContent, templateParams, outputFilename); callback(); } else { var templateFile = self.options.template; diff --git a/spec/HtmlWebpackPluginSpec.js b/spec/HtmlWebpackPluginSpec.js index e737806..fb3e162 100644 --- a/spec/HtmlWebpackPluginSpec.js +++ b/spec/HtmlWebpackPluginSpec.js @@ -83,6 +83,22 @@ describe('HtmlWebpackPlugin', function() { ['