Home > Software design >  NPM LINK how my team get the code while the shared module not push to npm or even registered at the
NPM LINK how my team get the code while the shared module not push to npm or even registered at the

Time:12-04

So I just try to use npm link for my multi project, everything work just fine for now, but one thing that i dont understand is since the shared folder not registered in the package.json and the node_modules folder not pushed to the remote repo then how my other team can get the code that being shared in my local ? it will done if i can change the directory of where the symlink will be placed (anywhere but not node_modules folder) Please help or give some explanation here Thanks

CodePudding user response:

When you use npm link on a local package, it creates a symlink from the global node_modules folder to the package's directory on your local machine. This allows other projects on your local machine to use the package as if it was installed from the registry, without needing to publish it or add it to the dependencies in their package.json.

However, this approach does not work for other members of your team, as the symlink is only created on your local machine. In order for other team members to use the shared package, you will need to either publish it to a registry (such as npm) or add it as a Git submodule in the repository.

To publish the package, you will need to create an account on a registry (such as npm) and follow the steps to publish your package. Once it is published, other team members can install it by running npm install in their project.

To add the package as a Git submodule, you can run the following commands in the root of your repository:

$ git submodule add <repository-url> shared
$ git submodule update --init --recursive

This will add the shared package as a submodule in the shared directory and initialize the submodules in the repository. Other team members can then clone the repository and run git submodule update --init --recursive to clone the submodule and initialize it in their local copy of the repository.

Once the shared package is added as a submodule or published to a registry, other team members can use it in their project by adding it to their dependencies in their package.json and running `npm

  • Related