diff --git a/index.js b/index.js index 2563513..0d7c569 100644 --- a/index.js +++ b/index.js @@ -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 { diff --git a/spec/HtmlWebpackPluginSpec.js b/spec/HtmlWebpackPluginSpec.js index 28f9d0a..80f3617 100644 --- a/spec/HtmlWebpackPluginSpec.js +++ b/spec/HtmlWebpackPluginSpec.js @@ -627,6 +627,20 @@ describe('HtmlWebpackPlugin', function() { }, [''], 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() + ] + }, ['