Generate module to module dependancy graph and resolve dependancy at build time
This plugin requires Grunt ~0.4.0
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-depgraph --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-depgraph');
Run this task with the grunt depgraph
command.
Type: Array
This defines what file patterns this task will watch. It will be an array of files.
Type: String
imtermediate generated dot file.
Type: String
path of the output file.
Type: Array
typeof output files. Example png, pdf
Example:
depgraph:{
options:{
files : ['src/js/modules/a.js',
'src/js/modules/b.js',
'src/js/modules/c.js']
dotFile: 'build/depGraph.dot',
outputFilePath: 'build/depGraph',
outputFilesExt: ['png','pdf'],
}
},
//src/js/modules/a.js
define({
'fileName' : 'MyLib',
'dependsOn' : [],
'layer' : 'Lib Layer'
}).content(function(){
return {
add : function(a,b){
return a+b;
},
sub : function(a,b){
return a-b;
}
}
});
//src/js/modules/b.js
define({
'fileName' : 'AddModule',
'dependsOn' : ['MyLib'],
'layer' : 'Module Layer'
}).content(function(Lib){
console.log('2 + 3 = ' + Lib.add(2,3));
});
//src/js/modules/c.js
define({
'fileName' : 'SubModule',
'dependsOn' : ['MyLib'],
'layer' : 'Module Layer'
}).content(function(Lib){
console.log('2 - 3 = ' + Lib.sub(2,3));
});
When you run grunt depgraph
, this will generate this image
sudo apt-get install graphviz
git clone https://github.com/nsisodiya/grunt-depgraph.git
cd grunt-depgraph/demo
npm install grunt
grunt depgraph
This will generate 'depGraph.png'
as you can see the example, this will generate depgraph! images your codebase has 1000 javascript files, you do not want to load all 1000 files, you only want to load 5 modules to your homepage and these 5 modules has some dependancy, then you can use this tool to generate a list of files which will be needed to load homepage
- 2013-08-29 v0.0.1 Intial base version.