Tell UglifyJS to skip a particular area of code

1.2k views Asked by At

Is there a way to tell UglifyJS to skip a particular section of code, perhaps using comments like this:

// uglifyjs:skipStart
filter = function(item){ /* some crazy filter logic that will repeat 500,000 times */ }
// uglifyjs:skipEnd

My use case has to do with avoiding the minification of a function that will be inlined and parsed in a custom way for performance gain. Minification breaks the simplified parser.

2

There are 2 answers

0
SimplGy On BEST ANSWER

Unfortunately, there is not a way to do this.

0
Kleanthis Tsesmetzidis On

The Global Definitions of Uglify Compressor is a feature you can use in order to conditionally drop code.

    global_defs: {
      DEBUG: false
    }

the compressor will assume that's a constant defintion and will discard code like this as being unreachable:

    if (DEBUG) {
      ...
    }

http://lisperator.net/uglifyjs/compress