Search code examples
javascriptnpmuglifyjs

Adding exceptions for some function from mangling with uglifyjs from command line


I am using uglifyjs to minimize and mangle a javascript file. I am using the following command

uglifyjs file.js -o file.min.js -c -m toplevel

I want to mangle the function names also, that's why I added toplevel as an option for -m(mangle) . However I want to add exceptions for some functions. I looked at the link: https://www.npmjs.com/package/uglify-js#mangler-options and gave the following command

uglifyjs file.js -o file.min.js -c -m toplevel -r 'fName1,fName2'

But that did not work and both the function names were still mangled. I am able to successfully add exception for a single function using the command

uglifyjs file.js -o file.min.js -c -m toplevel -r fName1

But I need a way to add exceptions for multiple functions.


Solution

  • On Windows, via Command Prompt, you need to wrap the exceptions in double quotes ("). For example:

    uglifyjs file.js -o file.min.js -c -m toplevel -r "fName1,fName2"