RemoveComments in html-minifier by command line

I want to use html-minifier

to minify my html files.

I installed it npm install -g html-minifier

However, sudo html-minifier rb.html --removeComments

did NOT delete comments in rb.html

.

Does anyone know how to use it?

Also, I just want to minimize the size of the html files while keeping the exact same layout, what are the normal options we put in html-minifier

?

+3


source to share


1 answer


You can target all html files in a specified directory with the following command:

html-minifier --input-dir dist --output-dir dist

      

In this example script, I compress all the html files into dist and output them to the same directory - essentially replacing the uncompressed html files with the compressed ones.

The above command doesn't actually do anything with the files, because no parameters were defined. Some useful options:



  • --collapse-whitespace

    : Collapse spaces that text nodes contribute to the document tree.
  • --remove-comments

    : Remove HTML comments
  • --minify-css

    : Minimizes built and built-in CSS ( <style></style>

    and style=""

    )
  • --minify-js

    : minimizes inline and inline JS ( <script></script>

    and eg onload=""

    )

Here is the command where you can:

html-minifier --input-dir dist --output-dir dist --remove-comments --collapse-whitespace --minify-js --minify-css

      

To see a complete list of available options, run html-minifier -h

.

+3


source







All Articles