From 23a0d9c338306150f46aaf8300c75efe40386949 Mon Sep 17 00:00:00 2001 From: Charles Blaxland Date: Tue, 12 Aug 2014 22:28:49 +1000 Subject: [PATCH] Support sourcemaps, which generate multiple output bundles for each entry --- index.js | 9 ++++++++- spec/HtmlWebpackPluginSpec.js | 31 ++++++++++++++++++++++--------- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index 3a3418c..a98825e 100644 --- a/index.js +++ b/index.js @@ -27,7 +27,14 @@ HtmlWebpackPlugin.prototype.htmlWebpackPluginJson = function(webpackStatsJson) { var json = {}; json.assets = {}; for (var chunk in webpackStatsJson.assetsByChunkName) { - json.assets[chunk] = webpackStatsJson.assetsByChunkName[chunk]; + var chunkValue = webpackStatsJson.assetsByChunkName[chunk]; + + // Webpack outputs an array for each chunk when using sourcemaps + if (chunkValue instanceof Array) { + // Is the main bundle always the first element? + chunkValue = chunkValue[0]; + } + json.assets[chunk] = chunkValue; } return json; diff --git a/spec/HtmlWebpackPluginSpec.js b/spec/HtmlWebpackPluginSpec.js index c26ca50..93d2337 100644 --- a/spec/HtmlWebpackPluginSpec.js +++ b/spec/HtmlWebpackPluginSpec.js @@ -6,10 +6,8 @@ var HtmlWebpackPlugin = require('../index.js'); var OUTPUT_DIR = path.join(__dirname, '..', 'dist'); -function testHtmlPlugin(webpackConfig, htmlPluginOptions, expectedResults, done) { +function testHtmlPlugin(webpackConfig, expectedResults, done) { var outputHtmlFile = path.join(OUTPUT_DIR, 'index.html'); - var htmlPlugin = htmlPluginOptions ? new HtmlWebpackPlugin(htmlPluginOptions) : new HtmlWebpackPlugin(); - webpackConfig.plugins = [htmlPlugin]; webpack(webpackConfig, function(err, stats) { expect(err).toBeFalsy(); expect(stats.hasErrors()).toBe(false); @@ -32,8 +30,9 @@ describe('HtmlWebpackPlugin', function() { output: { path: OUTPUT_DIR, filename: 'index_bundle.js' - } - }, null, ['