Add support for webpack.BannerPlugin

This commit is contained in:
Kees Kluskens 2015-09-09 13:28:10 +02:00
parent 6eb2d31c18
commit fcecadb5ee
2 changed files with 24 additions and 2 deletions

View File

@ -185,8 +185,16 @@ HtmlWebpackPlugin.prototype.evaluateCompilationResult = function(compilation, co
if(!compilationResult) {
return Promise.reject('The child compilation didn\'t provide a result');
}
// Strip the leading 'var '
var source = compilationResult.source().substr(3);
var source = compilationResult.source();
// Strip the leading 'var ' if present.
// If webpack.BannerPlugin is used, `source` starts with given comment.
if (_.startsWith(source, 'var')) {
source = source.substr(3);
} else {
// Replace first matching result variable, so that only a function is left.
source = source.replace('var result =', '');
}
// Evaluate code and cast to string
var newSource;
try {

View File

@ -627,6 +627,20 @@ describe('HtmlWebpackPlugin', function() {
}, ['<html lang="en" manifest="foo.appcache">'], null, done);
});
it('works with webpack bannerplugin', function(done) {
testHtmlPlugin({
entry: path.join(__dirname, 'fixtures/index.js'),
output: {
path: OUTPUT_DIR,
filename: 'index_bundle.js'
},
plugins: [
new webpack.BannerPlugin('Copyright and such.'),
new HtmlWebpackPlugin()
]
}, ['<html'], null, done);
});
it('shows an error when a template fails to load', function(done) {
testHtmlPlugin({
entry: path.join(__dirname, 'fixtures/index.js'),