Raise an error if both template and templateContent options are used together

This commit is contained in:
Charles Blaxland 2014-08-14 21:29:46 +10:00
parent 0b89ce7d20
commit 58d173c3d0
2 changed files with 21 additions and 1 deletions

View File

@ -18,7 +18,10 @@ HtmlWebpackPlugin.prototype.apply = function(compiler) {
var outputFilename = self.options.filename || 'index.html';
if (self.options.templateContent) {
if (self.options.templateContent && self.options.template) {
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);
callback();
} else {

View File

@ -83,6 +83,23 @@ describe('HtmlWebpackPlugin', function() {
['<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'),
output: {
path: OUTPUT_DIR,
filename: 'index_bundle.js'
},
plugins: [new HtmlWebpackPlugin({
template: path.join(__dirname, 'fixtures/test.html'),
templateContent: 'whatever'
})]
}, function(err, stats) {
expect(stats.hasErrors()).toBe(true);
expect(stats.toJson().errors[0]).toContain('HtmlWebpackPlugin');
done();
});
});
it('works with source maps', function(done) {
testHtmlPlugin({