Is there a way to mangle all variables except a specific one with gulp-uglify?
Basically, gulp is used to automate developer tasks as per their requirement, gulp provides the different types of features to the developer. In that, uglify is one of the features provided by the gulp. Basically uglify is used to avoid the error event if it is not able to minify our file.
Turn on use of name mangling cache to coordinate mangled symbols between outputted uglify files. uglify will the generate a JSON cache file with the name provided in the options. Note: this generated file uses the same JSON format as the exceptionsFiles files.
If a function is provided, the uglify destination is passed as the argument and the return value will be used as the file name. The location of an input source map from an earlier compilation, e.g. from CoffeeScript. If a function is provided, the uglify source is passed as the argument and the return value will be used as the sourceMap name.
That being said, if you already have a JSON file, you might as well reference it. You can also enable UglifyJS conditional compilation. This is commonly used to remove debug code blocks for production builds. This is equivalent to the command line --define option. See UglifyJS global definitions documentation for more information.
There definitely is, I couldn't find any documentation for gulp-uglify regarding these sub-options, so relied on grunt-uglify & wrote it the gulp way.
.pipe( uglify({ mangle: {except: ['jQuery']} }) ) // for gulp-uglify ^2.0.1
The above code will mangle every variable except jQuery
Hopefully this will still be useful for you. ;)
Sam.
========
NB: If you are using gulp-uglify ^3.0.0
please replace except
with reserved
eg:
.pipe( uglify({ mangle: {reserved: ['jQuery']} }) ) // for gulp-uglify ^3.0.0
Kudos to Lukas Winkler
That's right.
UglifyJS 3 except
was replaced with reserved
. Otherwise it will throw
DefaultsError: except` is not a supported option
it seem like this
.pipe(uglify({mangle: {reserved: ['$.loadEditor']}}))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With