Skip to content

Instantly share code, notes, and snippets.

@michaek
Last active August 29, 2015 14:02
Show Gist options
  • Save michaek/531c83e632836a0e1ee3 to your computer and use it in GitHub Desktop.
Save michaek/531c83e632836a0e1ee3 to your computer and use it in GitHub Desktop.
Uglify size comparison between mangled and non-mangled variable names (using Bootstrap as example)
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-uglify');
var files = [ grunt.option('js') || 'node_modules/bootstrap/js/*.js' ];
grunt.initConfig({
uglify: {
options: {
report: 'gzip'
},
mangle: {
files: {
'dist/mangle.js': files
}
},
no_mangle: {
options: {
mangle: false
},
files: {
'dist/no_mangle.js': files
}
}
}
});
grunt.registerTask('default', ['uglify:mangle', 'uglify:no_mangle']);
// $ grunt --no-color > output.txt
// $ grunt --no-color --js "some/other/js/**/*.js" > output.txt
}
Running "uglify:mangle" (uglify) task
File dist/mangle.js created: 54.98 kB → 28.85 kB → 5.09 kB (gzip)
Running "uglify:no_mangle" (uglify) task
File dist/no_mangle.js created: 54.98 kB → 35.15 kB → 5.94 kB (gzip)
Done, without errors.
{
"name": "uglify-test",
"version": "0.0.0",
"description": "",
"main": "Gruntfile.js",
"dependencies": {
"grunt": "~0.4.5",
"grunt-contrib-uglify": "~0.4.0"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment