To mangle toplevel variable/function names with UglifyJS, the following configuration can be used:

module.exports = function(grunt) {
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    uglify: {
      options: {
        mangle: {
          toplevel: true
        }
      },
      dist: {
        files: [{
          expand: true,
          cwd: '/some/directory',
          src: [
            'foo.js',
          ]
        }]
      }
    }
  });

  grunt.loadNpmTasks('grunt-contrib-uglify');

  grunt.registerTask('default', ['uglify']);

};