4

I have had some success minifying a .js file using terser. However, I have so far not been able to minify a standalone CSS file, and this is the reason for this qestion. I have installed html-minifier-terser, which minifies an HTML file, including any css or javascript code inside it (if the appropriate options are passed). My question is specifically with respect to minifying a standalone .css file: is there a terser command to minify a CSS file?

For example, the following command does not fully work for me (a new file is created with the whitespace removed, but /* ... */ comments are not):

html-minifier-terser mycss.css -o mycss.min.css --collapse-whitespace --remove-comments --minify-css true

(Also, using the javascript minifier does not work as the CSS is not legal javascript.)

sg1234
  • 600
  • 4
  • 19
  • 1
    This can be tested at https://terser.org/html-minifier-terser/ as well and the `--remove-comments` option only removes html comments. – AaronJ Feb 08 '22 at 14:58
  • If you're not required to use terser, then the standard tool for minifying CSS is https://www.npmjs.com/package/clean-css – thdoan Jun 19 '23 at 03:04
  • @thdoan Terser actually uses clean-css internally when minifying – exside Aug 26 '23 at 20:22

0 Answers0