1

I'm trying to use the --mange-regex option which is documented on UglifyJS2's GItHub README. The problem is, my build uses gulp-uglify, and it isn't clearly documented how I should use --mangle-regex without the command line.

My goal is to mangle 'private' identifiers (matching /^_/)

I've tried:

// Gulp setup code left out for brevity (I'm using gulp.src() etc properly)
uglify({
    mangle: {
        toplevel: false
    },
    mangleProperties: {
        regex: /^_/
    }
});

and

// Gulp setup code left out for brevity (I'm using gulp.src() etc properly)
uglify({
    mangle: {
        regex: /^_/
    }
});

Nothing's doin' here. A little help?

Bryan Rayner
  • 3,503
  • 3
  • 23
  • 36

2 Answers2

1

Turns out that the feature is only enabled in the master branch of Uglify as of this writing. The correct syntax, will be:

uglify({
    mangleProperties: {
        regex: /^_/
    }
});
Bryan Rayner
  • 3,503
  • 3
  • 23
  • 36
0

This is now supported but the syntax has changed a little. instead of mangleProperties it's now a 'properties' object inside a 'mangle' object:

Here's my complete code taken from my gulpfile.js, which works as of May 2020:

uglify        = require('gulp-uglify');

...

const uglifyOptions = {
    mangle: {
        properties: { regex: /^_/ }
    }
}

...

.pipe( uglify( uglifyOptions ) )