You can also use the requirejs configuration configuration to specify a mapping between your source module and your revved. Filerev displays a final object containing a map of all the modules that were version and their original names. Use the write function of the grunt file to write the file in AMD mode with the contents being the resulting object:
// Default task(s). grunt.registerTask('default', ['uglify', 'filerev', 'writeSummary']); grunt.registerTask('writeSummary', 'Writes the summary output of filerev task to a file', function() { grunt.file.write('filerevSummary.js', 'define([], function(){ return ' + JSON.stringify(grunt.filerev.summary) + '; })'); })
and use this file in your configuration file to use new updated modules instead of the old ones:
require(['../filerevSummary'], function(fileRev) { var filerevMap = {}; for (var key in fileRev) { var moduleID = key.split('/').pop().replace('.js', ''); var revvedModule = '../' + fileRev[key].replace('.js', ''); filerevMap[moduleID] = revvedModule; } require.config({ map: { '*': filerevMap } });
The filerevMap object that I created above is specific to my folder structure. You can customize it as you wish. It simply looks at the filerev summary and ensures that the keys are modified according to your module names and values according to your folder structure.
source share