14

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

4

4 回答 4

16

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

于 2015-08-12T10:04:25.107 回答
4

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']}}))

于 2017-07-16T09:20:10.877 回答
0

This work for me

.pipe(uglify({
  mangle: { toplevel: true, except: ['variable1', 'variable2',
  'function1'], 'function2' }
}))
于 2016-01-07T13:38:37.350 回答
0

You can use like this:

gulp.src(['src/*.js'])
    .pipe(uglify({
        mangle: {
            except: ['ExtensionId'] // (base on gulp-uglify v1.5.3)
        }
    }))
于 2016-03-12T15:02:36.617 回答