3

The default behaviour looks for @license or @preserve...

But many plugins and libraries are still using /*! for licensing comment blocks...

How can I use UglifyJS2 to preserve comments starting with /*! ?

ilovett
  • 3,240
  • 33
  • 39

2 Answers2

4

See https://github.com/mishoo/UglifyJS2#usage

Using the --comments argument, you can supply a regular expression.

uglifyjs jquery.plugin.js --comments '/^\/*!/' -o outfile.js
ilovett
  • 3,240
  • 33
  • 39
  • For me I had to do it without the quotes around the expression, eg. uglifyjs jquery.plugin.js --comments /^\/*!/ -o outfile.js – Jim W Mar 09 '16 at 17:08
1

In case that you use this VSCode extension JS & CSS Minifier (Minify), you can configure it easily. Just add a .uglifyrc file on your project root and add the following content to your file:

  {
      "output": {
        "comments": "/^\/*!/"
    }
  }

That will only preserve your license comments

SamuelCarreira
  • 101
  • 1
  • 4