Make gulp-uglify not mangle only one variable

随声附和 提交于 2019-12-08 14:58:09

问题


I just wanted to check if there is a way to mangle variables except a specific one for Gulp-Uglify. If there isn't, is there a work-around to achieve the effect I desire? Thanks.


回答1:


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




回答2:


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




回答3:


This work for me

.pipe(uglify({
  mangle: { toplevel: true, except: ['variable1', 'variable2',
  'function1'], 'function2' }
}))



回答4:


You can use like this:

gulp.src(['src/*.js'])
    .pipe(uglify({
        mangle: {
            except: ['ExtensionId'] // (base on gulp-uglify v1.5.3)
        }
    }))


来源:https://stackoverflow.com/questions/31694685/make-gulp-uglify-not-mangle-only-one-variable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!