Rolf
Rolf

Reputation: 53

Webpack removing empty html tags?

I use Webpack 4 with handlebars and there are many "default" optimizations for production mode I guess. I've googled about an hour for now and didn't find a solution...

In development mode empty tags are working. For example

<div class="test"></div>

or

<i class="fab fa-facebook" aria-hidden="true"></i>

If I add a non breaking space for example, the tags will be compiled in dist, but its very ugly...

<span class="caret">&nbsp;</span>

But after npm run build, these empty html tags are gone / stripped out. I have no idea why :(

Thanks for help!

Upvotes: 0

Views: 608

Answers (1)

lagerone
lagerone

Reputation: 1767

If you are using the HtmlWebpackPlugin in your webpack.config you can configure the minification like this:

new HtmlWebpackPlugin({
  minify: {
    removeEmptyElements: false,
  },
})

Upvotes: 1

Related Questions