3
votes

I'm using grunt uglify and it doesn't seem to be mangling variable names. My "God" object is called "Porsche" and it keeps that and all it's functions readable as you can see here:

enter image description here

And this is my Gruntfile config:

uglify: {
    options: {
        banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n',
        mangle: {
            except: ['jQuery', 'jquery']
        }
    },
    build: {
        src: [ 
            'assets/js/**/*.js'
        ],
        dest: 'assets/js/prod/all.min.js'
    }
}

I want it to completely mangle everything, saving bytes on function names. Is there anything I'm doing wrong?

2

2 Answers

4
votes

I have figured it out:

uglify: {
    options: {                  
        mangle: {
            toplevel: true
       }
    }
}
1
votes

You have to set mangle: false to prevent changes to your variable and function names:

uglify: {
    options: {
        banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n',
        mangle: false
    },
    build: {
        src: [ 
            'assets/js/**/*.js'
        ],
        dest: 'assets/js/prod/all.min.js'
    }
}

Check the documentation to see another example.