Skip to content

Instantly share code, notes, and snippets.

@iammerrick
Created March 16, 2014 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iammerrick/9587883 to your computer and use it in GitHub Desktop.
Save iammerrick/9587883 to your computer and use it in GitHub Desktop.
rjs-build-analysis example

The easiet implementation of the tool is to leverage rjs build time hooks, in our case we are leveraging done as added in the grunt-contrib-requirejs plugin. r.js build analysis leverages the format of manifest of build.txt that r.js provides in the case of the plugin we use the contents of that file provided directly via stdio. You could read the build.txt and invoke the analysis on that as well.

{
done: function(done, response) {
       var status = true;
       var duplicates = analyzer.duplicates(response, {
         exclude: ['publications/public/app.js']
       });
       grunt.util._.each(duplicates, function(parents, child) {
         grunt.log.subhead('The file "'+child+'" was built into the following multiple bundles: ');
         grunt.util._.each(parents, function(parent) {
           grunt.log.warn(parent);
         });
         grunt.log.writeln();
       });
       
       if (!grunt.util._.isEmpty(duplicates)) {
         status = false;
       }
       
       if (status === true) {
         grunt.log.writeln();
         grunt.log.writeln('No duplicates found in bundles.');
       }

       done(status);
     }
   })
}

As recently introduced I think building a tool on top of new hook is probably the right way to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment