diff --git a/default_index.html b/default_index.html index e79eae8..8cbdc80 100644 --- a/default_index.html +++ b/default_index.html @@ -1,15 +1,15 @@ - + {%=o.htmlWebpackPlugin.options.title || 'Webpack App'%} - {% for (var css in o.htmlWebpackPlugin.assets.css) { %} - + {% for (var css in o.htmlWebpackPlugin.files.css) { %} + {% } %} - {% for (var chunk in o.htmlWebpackPlugin.assets.chunks) { %} - + {% for (var chunk in o.htmlWebpackPlugin.files.chunks) { %} + {% } %} diff --git a/index.js b/index.js index 2d3cd30..e5b8360 100644 --- a/index.js +++ b/index.js @@ -15,7 +15,8 @@ HtmlWebpackPlugin.prototype.apply = function(compiler) { templateParams.webpack = webpackStatsJson; templateParams.hash = webpackStatsJson.hash; templateParams.htmlWebpackPlugin = {}; - templateParams.htmlWebpackPlugin.assets = self.htmlWebpackPluginAssets(compilation, webpackStatsJson); + templateParams.htmlWebpackPlugin.assets = self.htmlWebpackPluginLegacyAssets(compilation, webpackStatsJson); + templateParams.htmlWebpackPlugin.files = self.htmlWebpackPluginAssets(compilation, webpackStatsJson); templateParams.htmlWebpackPlugin.options = self.options; var outputFilename = self.options.filename || 'index.html'; @@ -66,7 +67,7 @@ HtmlWebpackPlugin.prototype.emitHtml = function(compilation, htmlTemplateContent HtmlWebpackPlugin.prototype.htmlWebpackPluginAssets = function(compilation, webpackStatsJson) { var assets = { // Will contain all js & css files by chunk - chunks: [], + chunks: {}, // Will contain all js files js: [], // Will contain all css files @@ -103,4 +104,18 @@ HtmlWebpackPlugin.prototype.htmlWebpackPluginAssets = function(compilation, webp return assets; }; +/** + * A helper to support the templates written for html-webpack-plugin <= 1.1.0 + */ +HtmlWebpackPlugin.prototype.htmlWebpackPluginLegacyAssets = function(compilation, webpackStatsJson) { + var assets = this.htmlWebpackPluginAssets(compilation, webpackStatsJson); + var legacyAssets = {}; + Object.keys(assets.chunks).forEach(function(chunkName){ + legacyAssets[chunkName] = assets.chunks[chunkName].entry; + }); + return legacyAssets; +}; + + + module.exports = HtmlWebpackPlugin; diff --git a/spec/HtmlWebpackPluginSpec.js b/spec/HtmlWebpackPluginSpec.js index 96a2cd0..717e105 100644 --- a/spec/HtmlWebpackPluginSpec.js +++ b/spec/HtmlWebpackPluginSpec.js @@ -83,6 +83,34 @@ describe('HtmlWebpackPlugin', function() { [' + + diff --git a/spec/fixtures/legacy_default_index.html b/spec/fixtures/legacy_default_index.html new file mode 100644 index 0000000..2595dd7 --- /dev/null +++ b/spec/fixtures/legacy_default_index.html @@ -0,0 +1,12 @@ + + + + + {%=o.htmlWebpackPlugin.options.title || 'Webpack App'%} + + + {% for (var chunk in o.htmlWebpackPlugin.assets) { %} + + {% } %} + + \ No newline at end of file diff --git a/spec/fixtures/test.html b/spec/fixtures/test.html index c209f70..2764033 100644 --- a/spec/fixtures/test.html +++ b/spec/fixtures/test.html @@ -6,6 +6,6 @@

Some unique text

- +