Uglifyjs: Option to prevent names from being mangled when calling UglifyJS.minify()

Created on 7 Apr 2015  路  5Comments  路  Source: mishoo/UglifyJS

When using UglifyJS.minify(), the property mangle can only be true or false so there is no way to enable mangling but set a list of reserved names as it can be done by ussing the --reserved parameter.

Is there any way of still using UglifyJS.minify(), enable mangling and specify those reserved names? If not, can you please consider adding that option?

enhancement

Most helpful comment

The mangle property can actually be an object. If you add the except property there, you can exclude variable names from mangling:

UglifyJS.minify('precious_file.js', {
  compress: true,
  mangle: {
    except: ['foozah']
  }
});

Please let me know if that doesn't solve your issue.

All 5 comments

The mangle property can actually be an object. If you add the except property there, you can exclude variable names from mangling:

UglifyJS.minify('precious_file.js', {
  compress: true,
  mangle: {
    except: ['foozah']
  }
});

Please let me know if that doesn't solve your issue.

@rvanvelzen Thanks for the quick response! That solved my problem.

Looking at the code I saw mangle could be an object but saw no code or documentation that described the content of that object. It would be great if a note can be added to the section The Simple Way or to document the object and its properties that can be passed as parameter in the call to mangle_names at Mangling.

Thanks, you are right - it only mentions that you can pass false to disable mangling. Lets keep this open until it is properly documented.

Finally I found this.
I took me several hours to find a way to reserve keywords from being mangled by specifying inside except, instead of reserved. To make it consistent with the command line that use --reserved, I suggest to use reserve.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alexlamsl picture alexlamsl  路  5Comments

lhtdesignde picture lhtdesignde  路  3Comments

JoeUX picture JoeUX  路  3Comments

andreialecu picture andreialecu  路  5Comments

Jimbly picture Jimbly  路  4Comments