Found the solution. Is it actually possible using the "onBuildWrite" configuration parameter , and specifying a callback that is executed before each module is serialized. Something like:
var config = {
baseUrl: 'src',
onBuildWrite: function( name, path, contents ) {
//Additional processing
return contents;
},
modules: [{
name: 'main'
}],
};
requirejs.optimize( config, function(results) {});