Skip to content

Instantly share code, notes, and snippets.

@archangel-irk
Last active December 23, 2015 21:29
Show Gist options
  • Save archangel-irk/6696847 to your computer and use it in GitHub Desktop.
Save archangel-irk/6696847 to your computer and use it in GitHub Desktop.
grunt hash (.md5) checksum file for uglify.
uglify: {
production: {
options: {
report: 'min'
},
files: [{
expand: true,
cwd: '<%= dir.tempJS %>/',
src: '*.js',
dest: '<%= dir.publicJS %>',
rename: function( dest, srcName, options ){
// Calculate md5 hash
var
fs = require('fs'),
crypto = require('crypto'),
md5 = crypto.createHash('md5'),
pathToFile = grunt.template.process( options.cwd + srcName ),
buffer = fs.readFileSync( pathToFile ),
fileName = srcName.replace('.js', '');
md5.update( buffer );
var md5Hash = md5.digest('hex');
return dest + '/' + fileName + '.min.' + md5Hash + '.js';
}
}]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment