Allow to pass a function for custom html rendering / templating
This commit is contained in:
parent
6a140b5085
commit
2815661681
3
index.js
3
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;
|
||||
|
|
|
|||
|
|
@ -83,6 +83,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'),
|
||||
|
|
|
|||
Loading…
Reference in New Issue