In this post I will talk about npm link, however, if you just replace npm
with bower
you will be able to perform the same feature. There is one difference to note though. To have bower link
work you must be in the directory where the bower.json
file resides instead of the package.json
file. Most of the time they reside in the same location, but sometimes they do not.
npm/bower link
NPM/Bower link is a great feature from npm/bower that allows you to instead of copying and pasted code changes in one project to another via IDE, or performing a git push to one project and then doing an npm install in the other in order to get the latest changes, you can create a globally-installed symbolic link that enables the local changes from your dev module and includes it in your application that requires it. This allows you to make changes one place and they in effect in real time in the other, so there is no need to do worry about copying and pasting code from a project dependent upon a npm package
Now npm link is super easy to use. Basically, you can get this great feature by just performing these easy steps.
- cd into the forked/cloned repo directory (where package.json exists) of the npm dependency you want to link to your main project. For example, if project A depends on project B then cd into where project B resides.
- Perform
npm link
command. This command will use thename:
field in your package.json file as the name for the symbolic link. - cd into the project that is dependent upon your linking project. For example, if project A depends on project B then cd into project A where the package.json file resides.
- Perform
npm link projectB
whereprojectB
is your project name that you performed the first npm link on.
And thats it!! Now your projects are linked together for development on both projects at the same time. Now that's being productive. One thing I would like to mention is that when you delete your node_modules
directory this will remove the symbolic link, so you will have to perform step 3 and 4 again to reestablish the global link again.