Skip to content

Commit

Permalink
fix: don't remove trailing slashes from self closing tags by default
Browse files Browse the repository at this point in the history
  • Loading branch information
jantimon committed Mar 26, 2020
1 parent d1b173f commit 2281e4b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
5 changes: 3 additions & 2 deletions index.js
Expand Up @@ -115,10 +115,11 @@ class HtmlWebpackPlugin {

const minify = this.options.minify;
if (minify === true || (minify === 'auto' && isProductionLikeMode)) {
/** @type { import('html-minifier').Options } */
/** @type { import('html-minifier-terser').Options } */
this.options.minify = {
// https://github.com/kangax/html-minifier#options-quick-reference
// https://www.npmjs.com/package/html-minifier-terser#options-quick-reference
collapseWhitespace: true,
keepClosingSlash: true,
removeComments: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
Expand Down
23 changes: 23 additions & 0 deletions spec/basic.spec.js
Expand Up @@ -2304,4 +2304,27 @@ describe('HtmlWebpackPlugin', () => {
]
}, [/<script defer="defer".+<link href="styles.css"/], null, done);
});

it('should keep closing slashes from the template', done => {
testHtmlPlugin({
mode: 'production',
entry: path.join(__dirname, 'fixtures/theme.js'),
output: {
path: OUTPUT_DIR,
filename: 'index_bundle.js'
},
module: {
rules: [
{ test: /\.css$/, use: [MiniCssExtractPlugin.loader, 'css-loader'] }
]
},
plugins: [
new HtmlWebpackPlugin({
scriptLoading: 'defer',
templateContent: '<html><body> <selfclosed /> </body></html>'
}),
new MiniCssExtractPlugin({ filename: 'styles.css' })
]
}, [/<selfclosed\/>/], null, done);
});
});

0 comments on commit 2281e4b

Please sign in to comment.