magiclen / html-minifier

This library can help you generate and minify your HTML code at the same time. It also supports to minify JS and CSS in `<style>`, `<script>` elements, and ignores the minification of `<pre>` elements.
MIT License
21 stars 5 forks source link

wrong minification of CSS comments #9

Closed koalp closed 3 years ago

koalp commented 3 years ago

For some situations where I have comments in <style> tags, the minified CSS is wrong and doesn't correspond to the original css.

As an example, minifying

<!DOCTYPE html>
<html>
    <head>
        <style>
            .test1 {
                font-weight: 30em;
            }/**/
            .test2 {
            }/**/
            .test3 {
            }/**/
        </style>
    </head>
    <body>
    </body>
</html>

gives me

<!DOCTYPE html>
<html>
<head>
<style>.test1{font-weight:30em;}/*!/
            .test2 {
            }/**/
.test3{}
        </style>
</head>
<body>
</body>
</html>

(notice the /*!/ that makes .test2 part of the comment)

koalp commented 3 years ago

It seems that it is due to the CSS minifying library used. I opened an issue in the minifier-rs repository : https://github.com/GuillaumeGomez/minifier-rs/issues/69

edit: it have been solved in minifier-rs 0.0.40

magiclen commented 3 years ago

A very quick fix, nice!!