terser / html-minifier-terser

actively maintained fork of html-minifier - minify HTML, CSS and JS code using terser - supports ES6 code
https://terser.org/html-minifier-terser
MIT License
376 stars 30 forks source link

after set "conservativeCollapse: false", still leave a white space between html elements #26

Closed snoleo closed 4 years ago

snoleo commented 4 years ago

Expected behaviour

with "conservativeCollapse: false", it should remove white spaces between html elements entirely.

<div><a href="#">123</a><a href="#">456</a><a href="#">test 3</a></div>

Current behaviour

Still leave a white space between html elements.

<div><a href="#">123</a> <a href="#">456</a> <a href="#">test 3</a></div>

Environment

Node.js v12.14.0
linux 5.0.0-37-generic
npm 6.13.4
webpack@4.41.4
html-webpack-plugin@3.2.0

Config

  plugins: [
    new HtmlWebpackPlugin({
      chunks: ['index'],
      template: './src/index.html',
      filename: './index.html',
      minify: { removeComments: true, removeEmptyAttributes: true, removeRedundantAttributes: false, collapseWhitespace: true, conservativeCollapse: false }
    }),
    new HtmlWebpackPlugin({
      chunks: ['sub'],
      template: './src/sub.html',
      filename: './sub.html',
      minify: { removeComments: true, removeEmptyAttributes: true, removeRedundantAttributes: false, collapseWhitespace: true, conservativeCollapse: false }
    })
  ],

Copy your template file if it is part of this issue:

<!DOCTYPE html>
<html>
    <head>
        <title>My App</title>
    </head>
    <body>
                <div>
                        <a href="#">123</a>
                        <a href="#">456</a>
                        <a href="#">test 3</a>
                </div>
    </body>
</html>

Relevant Links

Additional context

DanielRuf commented 4 years ago

with "conservativeCollapse: false", it should remove white spaces between html elements entirely.

Normally not, also see https://github.com/kangax/html-minifier/issues/834

Removing the spaces between your anchors would create a different output which is broken then.

http://perfectionkills.com/experimenting-with-html-minifier/#cost_and_benefits

DanielRuf commented 4 years ago

https://github.com/DanielRuf/html-minifier-terser/blob/583e0861ee852a76acb1e8ec00b3de35a024927d/src/htmlminifier.js#L66-L69

https://github.com/DanielRuf/html-minifier-terser/blob/583e0861ee852a76acb1e8ec00b3de35a024927d/src/htmlminifier.js#L76

https://github.com/DanielRuf/html-minifier-terser/blob/583e0861ee852a76acb1e8ec00b3de35a024927d/src/htmlminifier.js#L80

https://github.com/DanielRuf/html-minifier-terser/blob/583e0861ee852a76acb1e8ec00b3de35a024927d/src/htmlminifier.js#L1131

https://github.com/DanielRuf/html-minifier-terser/blob/583e0861ee852a76acb1e8ec00b3de35a024927d/src/htmlminifier.js#L1172

DanielRuf commented 4 years ago

Closing as there is no further feedback.