Mangle all variables except one with gulp-uglify

deleted picture deleted · Jul 29, 2015 · Viewed 7.4k times · Source

Is there a way to mangle all variables except a specific one with gulp-uglify?

Answer

Sam picture Sam · Aug 12, 2015

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