When deploying my app on a test server, I came with an error where UglifyJS did change a npm dependency module's functions arguments, where the names of these arguments are important; some functions are called dynamically and I am using function-arguments to map certain values to certain function arguments based on their corresponding names.
Is it possible to tell UglifyJS to skip certain modules, or files, etc.?
According to the documentation you can use mangle options to for that:
mangle (default true) — pass false to skip mangling names, or pass an object to specify mangling optionsObject options:
except - pass an Array of identifiers that should be excluded from manglingtoplevel — mangle names declared in the toplevel scope (disabled by default).eval — mangle names visible in scopes where eval or with are used (disabled by default).keep_fnames -- default false. Pass true to not mangle function names. Useful for code relying on Function.prototype.name.//tst.js
var globalVar;
function funcName(firstLongName, anotherLongName)
{
var myVariable = firstLongName + anotherLongName;
}
UglifyJS.minify("tst.js").code;
// 'function funcName(a,n){}var globalVar;'
UglifyJS.minify("tst.js", { mangle: { except: ['firstLongName'] } }).code;
// 'function funcName(firstLongName,a){}var globalVar;'
UglifyJS.minify("tst.js", { mangle: { toplevel: true } }).code;
// 'function n(n,a){}var a;'
I tried to find an option to mangle the function names and skip mangling the arguments and didn't fun that so far (not saying there isn't...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With