Webpack 删除空 html 标签?
Webpack removing empty html tags?
我将 Webpack 4 与 handlebars 一起使用,我猜 "default" 生产模式有很多优化。我已经用谷歌搜索了大约一个小时,但没有找到解决方案...
在开发模式下,空标签可以正常工作。例如
<div class="test"></div>
或
<i class="fab fa-facebook" aria-hidden="true"></i>
如果我添加一个非中断 space 例如,标签将在 dist 中编译,但它非常丑陋...
<span class="caret"> </span>
但是在 npm 运行 构建之后,这些空的 html 标签消失了/被剥离了。我不知道为什么:(
感谢帮助!
如果您在 webpack.config
中使用 HtmlWebpackPlugin
,您可以像这样配置缩小:
new HtmlWebpackPlugin({
minify: {
removeEmptyElements: false,
},
})
我将 Webpack 4 与 handlebars 一起使用,我猜 "default" 生产模式有很多优化。我已经用谷歌搜索了大约一个小时,但没有找到解决方案...
在开发模式下,空标签可以正常工作。例如
<div class="test"></div>
或
<i class="fab fa-facebook" aria-hidden="true"></i>
如果我添加一个非中断 space 例如,标签将在 dist 中编译,但它非常丑陋...
<span class="caret"> </span>
但是在 npm 运行 构建之后,这些空的 html 标签消失了/被剥离了。我不知道为什么:(
感谢帮助!
如果您在 webpack.config
中使用 HtmlWebpackPlugin
,您可以像这样配置缩小:
new HtmlWebpackPlugin({
minify: {
removeEmptyElements: false,
},
})