A simple development skills article. Mainly in peacetime development, there are NPM packages need to be debugged locally and then released. It’s not elegant to send a version to test, or copy and paste code into a project folder to debug. The soft chain becomes extremely useful, especially if you need to debug more than one NPM package and tune with each other.
1. What is soft chain?
Simply put, create a global link for the developed module (the NPM package to be released), link the dependent module in the main project, and test it.
2. How to create, use and remove soft chains?
2.1 Create a global link in the file of the corresponding NPM package
cd ~/projects/package-project
npm link
Copy the code
2.2 Then use the soft chain in projects that want to use the package
PackageName must correspond to the name field in your package.json package.
cd ~/projects/package-project
npm link packageName
Copy the code
Well, with the previous two steps, we can now use the locally located NPM package 😊 in the main project.
2.3 How to remove the soft chain after use?
The order of the next two steps, I tried to reverse the order actually did not report mistakes. But since some students have raised it, I think it is logically more reasonable to remove the global link package first.
2.31 First unlink specific links in the file directory of the project using the NPM package
npm unlink packageName
Copy the code
2.32 Remove global links in the directory where the NPM package resides
npm unlink
Copy the code
This is actually OK, but if you want to:
2.33 Forcibly disconnecting a specific global link
sudo npm rm --global packageName
Copy the code
2.34 Viewing the Names of All Created Global links
npm ls --global --depth 0
Copy the code