1

I often use empty functions as HereDoc blocks when templating.

var heredoc = function() {/*
  <div>
    Hello World!
  </div>
*/};

The UglifyJS2 compressor removes all comments, which is generally desirable. Except for this one! I thought to use "--comments" on the command-line and "/** @preserve" in the comment block, which did not work. I also tried regular expressions. Here is a specific command I tried on the above JS file:

uglifyjs test.js -o test.min.js -p 5 -c -m --comments /div/i

And the result was as follows:

var heredoc=function(){};

I'm finding it difficult to get any regular expression to work at all...

/* div keep me */
var heredoc = function() {/** @preserve
  <div>
    Hello World!
  </div>
*/};

heredoc();

placement of the comment inside or outside; calling the function directly or not. Nothing is working.

uglify-js 2.6.1

Nathan
  • 151
  • 2
  • 16

1 Answers1

1

This is not a very acceptable answer, but I will offer it anyways.

This is working:

var heredoc = function() {/** @preserve
  <div>
    Hello World!
  </div>
*/""};

I added the empty string at the bottom after reading another question:

UglifyJS2 removes wanted comments at the end of a block or file

However, it did not work using regex. I had to use the jsdoc @preserve tag.

Community
  • 1
  • 1
Nathan
  • 151
  • 2
  • 16