Grunt task to handle the linking of local dependencies.
This task is useful if you have a large app and instead of requiring directories directly that should be their own module you can now develop your modules independently and link them using this task.
This allows you to develop as if it were its own module and if you ever decide to publish your modules you just have to change your
package.json and your code does not have to change.
This also allows you develop your modules in isolation with their own respective dependencies and tests.
For example assume you have an app of the following structure.
You could develop each module in isolation and link them.
Install this grunt plugin next to your project's grunt.js gruntfile with:
npm install grunt-link
Then add this line to your project's
In each modules
package.json add a
linkDependencies array which is an array of local modules that need to be linked.
"name": "my-module""version" : "0.0.1""linkDependencies":"module-a""module-b""module-c"
To run from the command line you can run
grunt link which will link your modules.
When running grunt link will determine the link order of your modules, if it detects cyclic dependencies while determining the link order then it will produce an error.
To prevent the warning for a single module you can add
! to the beginning of the dependency name in the
"name": "my-module""version" : "0.0.1""linkDependencies":"!module-a""module-b""module-c"
Note you will not be able to directly require the module you will have to require lazily.
To prevent this default behavior you can add the following to your
grunt-link will look for modules in the same directory as your
grunt.js file if you wish to link modules in another directory you can add the following to your
dir is relative to to grunt.js file.
install default true
grunt-link will run
npm install on each linked module if you wish to just link your modules you can set this option to false.
clean default true
grunt-link will by default remove the node_modules directory to prevent this set
clean to false.
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using grunt.
npm linkwhen initially linking modules
package.jsonfor correct repo
npm linkto improve performance.
2012-12-30 v0.0.1 Initial release.
Copyright (c) 2012 Doug Martin
Licensed under the MIT license.