From 67ae8e074652c5ee298535da5c6a60514d4fc394 Mon Sep 17 00:00:00 2001 From: Charles Blaxland Date: Wed, 13 Aug 2014 09:30:27 +1000 Subject: [PATCH] Add support for specifying the title of the generated HTML --- default_index.html | 2 +- index.js | 13 +++++++------ spec/HtmlWebpackPluginSpec.js | 14 ++++++++++---- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/default_index.html b/default_index.html index b5d6a91..cf521f4 100644 --- a/default_index.html +++ b/default_index.html @@ -2,7 +2,7 @@ - Webpack App + {%=o.htmlWebpackPlugin.options.title || 'Webpack App'%} {% for (var chunk in o.htmlWebpackPlugin.assets) { %} diff --git a/index.js b/index.js index b8b83a3..a8fde22 100644 --- a/index.js +++ b/index.js @@ -12,7 +12,9 @@ HtmlWebpackPlugin.prototype.apply = function(compiler) { var webpackStatsJson = stats.toJson(); var templateParams = {}; templateParams.webpack = webpackStatsJson; - templateParams.htmlWebpackPlugin = self.htmlWebpackPluginJson(compiler, webpackStatsJson); + templateParams.htmlWebpackPlugin = {}; + templateParams.htmlWebpackPlugin.assets = self.htmlWebpackPluginAssets(compiler, webpackStatsJson); + templateParams.htmlWebpackPlugin.options = self.options; var templateFile = self.options.template; if (!templateFile) { @@ -23,9 +25,8 @@ HtmlWebpackPlugin.prototype.apply = function(compiler) { }); }; -HtmlWebpackPlugin.prototype.htmlWebpackPluginJson = function(compiler, webpackStatsJson) { - var json = {}; - json.assets = {}; +HtmlWebpackPlugin.prototype.htmlWebpackPluginAssets = function(compiler, webpackStatsJson) { + var assets = {}; for (var chunk in webpackStatsJson.assetsByChunkName) { var chunkValue = webpackStatsJson.assetsByChunkName[chunk]; @@ -38,10 +39,10 @@ HtmlWebpackPlugin.prototype.htmlWebpackPluginJson = function(compiler, webpackSt if (compiler.options.output.publicPath) { chunkValue = compiler.options.output.publicPath + chunkValue; } - json.assets[chunk] = chunkValue; + assets[chunk] = chunkValue; } - return json; + return assets; }; module.exports = HtmlWebpackPlugin; diff --git a/spec/HtmlWebpackPluginSpec.js b/spec/HtmlWebpackPluginSpec.js index d978c5c..529e05b 100644 --- a/spec/HtmlWebpackPluginSpec.js +++ b/spec/HtmlWebpackPluginSpec.js @@ -83,7 +83,6 @@ describe('HtmlWebpackPlugin', function() { it('handles hashes in bundle filenames', function(done) { testHtmlPlugin({ - devtool: 'sourcemap', entry: path.join(__dirname, 'fixtures', 'index.js'), output: { path: OUTPUT_DIR, @@ -95,7 +94,6 @@ describe('HtmlWebpackPlugin', function() { it('prepends the webpack public path to script src', function(done) { testHtmlPlugin({ - devtool: 'sourcemap', entry: path.join(__dirname, 'fixtures', 'index.js'), output: { path: OUTPUT_DIR, @@ -108,7 +106,6 @@ describe('HtmlWebpackPlugin', function() { it('handles subdirectories in the webpack output bundles', function(done) { testHtmlPlugin({ - devtool: 'sourcemap', entry: path.join(__dirname, 'fixtures', 'index.js'), output: { path: OUTPUT_DIR, @@ -118,7 +115,6 @@ describe('HtmlWebpackPlugin', function() { }, ['