role

During development, a package can be linked to another project.

Usually used when testing new functionality or trying to debug a problem that the package presents in another project.

use

What do we do when we need to use another locally developed package, link-Module, while developing project Project-a?

NPM Link is used in the same way as YARN link. This document uses NPM Link as an example

1. CD Go to the link-module directory and run the NPM link command.

2. Go to project -a and run the NPM link link-module command.

3. Use the link-module package directly in project-a;

project-A > index.js

require("link-module");
Copy the code

At this point, any changes we make in the link-Module package will be reflected in project-a in time.

4. If you do not want to use the link-module, run the NPM unlink link-module command to disconnect the link.

The principle of

Links are essentially soft links that allow us to quickly use other packages that are being developed locally.

Let’s analyze the next step

NPM link = NPM link = NPM link

/usr/local/lib/node_modules/link-module -> /Users/shiyou/Desktop/link-module
Copy the code

In /usr/local/lib/node_modules/public package management path connect to the local link-module package.

So when we run the NPM link link-module command in project -a, it will go to /usr/local/lib/node_modules/to see if there is this package, and if there is, it will create A soft link.