1
votes

I am using r.js with uglify to minify and concatenate my scripts. I am getting some errors on a production site where the stack trace returned is unintelligible. I would like to temporarily turn off the mangling of function names (variable names are fine) and am having trouble working out how to do this as r.js wraps the configuration options that are passed to uglify.js

The uglify config section in my r,js build config looks like this

uglify: {
      beautify: true,
      indent_start: 0,
      indent_level: 1,
   }

I would like to add the

-nmf or --no-mangle-functions – in case you want to mangle variable names, but not touch function names. (from here)

If i add the line

uglify: {
      beautify: true,
      indent_start: 0,
      indent_level: 1,
      '--no-mangle-functions': true
   }

It does nothing, as does 'no-mangle-functions': true.

How do I pass this option to uglify?

2
have you seen the example config file on their webpage: github.com/jrburke/r.js/blob/master/build/example.build.js ? There is this no_mangle: true option and a mangle : falseoption for r.js version 2 - pfried
Yes, but this option only allows mangling or not, it does not allow you access to the full mangling options (I want to mangle the variable names, but not the function names) - Aran Mulholland

2 Answers

3
votes

Trying to make uglified/mangled code readable kind of defeats it's purpose in the first place. Probably, what you are after are source maps.

To generate source maps in Uglify just add these options:

uglify: {
    options: {
        sourceMap: 'build.min.map',
        sourceMappingURL: 'build.min.map'
    }
}

Map filename must mirror the final javascript filename:

uglified.js <=> uglified.map
1
votes

From what i can see in the source code of r.js there is no direct differentiation between functions and variable names. But there is an option called no_functions which is actually passed to the uglify section where the default value is false

Passing of options:

https://github.com/jrburke/r.js/blob/master/dist/r.js#L25067

Defaulting no_functionsto false:

https://github.com/jrburke/r.js/blob/master/dist/r.js#L11492

I cannot test it right now, so i am only guessing. Maybe you can try this option