gulpuglifyjsgulp-uglifyuglifyjs2

Uglify.js - how to mangle just SOME global variable/function names (using Grunt)


Hi,

I'm using Grunt and Uglify.js to mangle my code and I found out that by default the global function/variable names are not mangled, which makes sense.

I then found out, that there is a way on how to mangle them with using some settings but than ALL the global variables get mangled.

I need a way to mangle about half (some of them) of my variable/function names, not all of them, is there a way to achieve this?

I have no problem telling Grunt which to mangle and which not to but I cant find a solution to this...

Thank you


Solution

  • From the uglify mangle options:

    reserved (default []) -- Pass an array of identifiers that should be excluded from mangling. Example: ["foo", "bar"].

    so use this option to your uglify call:

    { mangle: { reserved: ['dontMangleMe1', 'dontMangleMe2'] } }
    

    You don't show any code and you talk about grunt but chose gulp tags for your question so I don't know how your are calling uglify.