From bf5901e5c0da5a0f36f88aa1f9b73c3e3315e4fa Mon Sep 17 00:00:00 2001 From: Koen Punt Date: Tue, 15 Mar 2016 12:31:28 +0100 Subject: [PATCH 1/2] Add xhtml option to make link tags self-closing --- index.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 7838ba1..ea0c0ce 100644 --- a/index.js +++ b/index.js @@ -23,7 +23,8 @@ function HtmlWebpackPlugin (options) { showErrors: true, chunks: 'all', excludeChunks: [], - title: 'Webpack App' + title: 'Webpack App', + xhtml: false }, options); } @@ -415,9 +416,11 @@ HtmlWebpackPlugin.prototype.injectAssetsIntoHtml = function (html, assets) { var scripts = assets.js.map(function (scriptPath) { return ''; }); + // Make tags self-closing in case of xhtml + var xhtml = this.options.xhtml ? '/' : ''; // Turn css files into link tags var styles = assets.css.map(function (stylePath) { - return ''; + return ''; }); // Injections var htmlRegExp = /(]*>)/i; @@ -428,7 +431,7 @@ HtmlWebpackPlugin.prototype.injectAssetsIntoHtml = function (html, assets) { // If there is a favicon present, add it to the head if (assets.favicon) { - head.push(''); + head.push(''); } // Add styles to the head head = head.concat(styles); From f8abc156b51c2480e0e7256d98bc64800b526201 Mon Sep 17 00:00:00 2001 From: Koen Punt Date: Tue, 15 Mar 2016 13:50:12 +0100 Subject: [PATCH 2/2] Add xhtml option to readme and add tests --- README.md | 1 + spec/HtmlWebpackPluginSpec.js | 39 ++++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6b26e44..8c82dbc 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,7 @@ Allowed values are as follows: - `chunks`: Allows you to add only some chunks (e.g. only the unit-test chunk) - `chunksSortMode`: Allows to control how chunks should be sorted before they are included to the html. Allowed values: 'none' | 'auto' | 'dependency' | {function} - default: 'auto' - `excludeChunks`: Allows you to skip some chunks (e.g. don't add the unit-test chunk) +- `xhtml`: `true | false` If `true` render the `link` tags as self-closing, XHTML compliant. Default is `false` Here's an example webpack config illustrating how to use these options: ```javascript diff --git a/spec/HtmlWebpackPluginSpec.js b/spec/HtmlWebpackPluginSpec.js index 65dadf1..5be9cfa 100644 --- a/spec/HtmlWebpackPluginSpec.js +++ b/spec/HtmlWebpackPluginSpec.js @@ -394,7 +394,7 @@ describe('HtmlWebpackPlugin', function () { new HtmlWebpackPlugin(), new ExtractTextPlugin('styles.css') ] - }, [''], null, done); }); it('should work with the css extract plugin on windows and protocol relative urls support (#205)', function (done) { @@ -478,6 +478,26 @@ describe('HtmlWebpackPlugin', function () { }, [''], null, done); + }); + it('prepends the webpack public path to script src', function (done) { testHtmlPlugin({ entry: path.join(__dirname, 'fixtures/index.js'), @@ -893,6 +913,23 @@ describe('HtmlWebpackPlugin', function () { }, [//], null, done); }); + it('adds a favicon with xhtml enabled', function (done) { + testHtmlPlugin({ + entry: path.join(__dirname, 'fixtures/index.js'), + output: { + path: OUTPUT_DIR, + filename: 'index_bundle.js' + }, + plugins: [ + new HtmlWebpackPlugin({ + inject: true, + xhtml: true, + favicon: path.join(__dirname, 'fixtures/favicon.ico') + }) + ] + }, [//], null, done); + }); + it('shows an error if the favicon could not be load', function (done) { testHtmlPlugin({ entry: path.join(__dirname, 'fixtures/index.js'),