Skip to content

Instantly share code, notes, and snippets.

@druzn3k
Forked from archangel-irk/grunt-hash.js
Created May 10, 2014 09:07
Show Gist options
  • Save druzn3k/7202e642d9bca1789c6c to your computer and use it in GitHub Desktop.
Save druzn3k/7202e642d9bca1789c6c to your computer and use it in GitHub Desktop.
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