Merge branch 'feature/template-function' of https://github.com/jantimon/html-webpack-plugin into jantimon-feature/template-function

Conflicts:
	index.js
This commit is contained in:
Charles Blaxland 2015-03-30 12:09:09 +11:00
commit 4d74f4b061
2 changed files with 18 additions and 1 deletions

View File

@ -26,7 +26,8 @@ HtmlWebpackPlugin.prototype.apply = function(compiler) {
compilation.errors.push(new Error('HtmlWebpackPlugin: cannot specify both template and templateContent options'));
callback();
} else if (self.options.templateContent) {
self.emitHtml(compilation, self.options.templateContent, templateParams, outputFilename);
var templateContent = typeof self.options.templateContent === 'function' ? self.options.templateContent(templateParams, compiler) : self.options.templateContent;
self.emitHtml(compilation, templateContent, templateParams, outputFilename);
callback();
} else {
var templateFile = self.options.template;

View File

@ -112,6 +112,22 @@ describe('HtmlWebpackPlugin', function() {
['<script src="app_bundle.js'], null, done);
});
it('allows you to specify your own HTML template function', function(done) {
testHtmlPlugin({
entry: {app: path.join(__dirname, 'fixtures/index.js')},
output: {
path: OUTPUT_DIR,
filename: 'app_bundle.js'
},
plugins: [new HtmlWebpackPlugin({
templateContent: function() {
return fs.readFileSync(path.join(__dirname, 'fixtures/test.html'), 'utf8');
}
})]
},
['<script src="app_bundle.js"'], null, done);
});
it('registers a webpack error both template and template content are specified', function(done) {
webpack({
entry: path.join(__dirname, 'fixtures/index.js'),