Skip to content

Commit 2281e4b

Browse files
committed
fix: don't remove trailing slashes from self closing tags by default
1 parent d1b173f commit 2281e4b

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,11 @@ class HtmlWebpackPlugin {
115115

116116
const minify = this.options.minify;
117117
if (minify === true || (minify === 'auto' && isProductionLikeMode)) {
118-
/** @type { import('html-minifier').Options } */
118+
/** @type { import('html-minifier-terser').Options } */
119119
this.options.minify = {
120-
// https://github.com/kangax/html-minifier#options-quick-reference
120+
// https://www.npmjs.com/package/html-minifier-terser#options-quick-reference
121121
collapseWhitespace: true,
122+
keepClosingSlash: true,
122123
removeComments: true,
123124
removeRedundantAttributes: true,
124125
removeScriptTypeAttributes: true,

spec/basic.spec.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2304,4 +2304,27 @@ describe('HtmlWebpackPlugin', () => {
23042304
]
23052305
}, [/<script defer="defer".+<link href="styles.css"/], null, done);
23062306
});
2307+
2308+
it('should keep closing slashes from the template', done => {
2309+
testHtmlPlugin({
2310+
mode: 'production',
2311+
entry: path.join(__dirname, 'fixtures/theme.js'),
2312+
output: {
2313+
path: OUTPUT_DIR,
2314+
filename: 'index_bundle.js'
2315+
},
2316+
module: {
2317+
rules: [
2318+
{ test: /\.css$/, use: [MiniCssExtractPlugin.loader, 'css-loader'] }
2319+
]
2320+
},
2321+
plugins: [
2322+
new HtmlWebpackPlugin({
2323+
scriptLoading: 'defer',
2324+
templateContent: '<html><body> <selfclosed /> </body></html>'
2325+
}),
2326+
new MiniCssExtractPlugin({ filename: 'styles.css' })
2327+
]
2328+
}, [/<selfclosed\/>/], null, done);
2329+
});
23072330
});

0 commit comments

Comments
 (0)