Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use npm workspace

I develop my app by using npm workspace.but I am totally novice to this concept so that I would like to understand npm workspace behavior

.
├── package.json
└── packages
    ├── a
    │   └── package.json
    ├── b
    │   └── package.json
    └── c
        └── package.json

package.json

{
  "workspaces": [
    "packages/*"
  ]
}

My question is

①what happens when I run npm install in root directory ? All the packages are installed in each repository ? or root directory ?

npm install in each project is not recommended ?

if someone has opinion, will you please let me know. Thanks

like image 732
Heisenberg Avatar asked Oct 16 '25 08:10

Heisenberg


1 Answers

So long as all packages have the same version of dependencies listed (e.g. [email protected]), then npm install run from the root of your repository will add the dependency into the root node_modules directory.

If one of your packages (e.g. packages/c) has a different version of a dependency (e.g. [email protected]) then that would appear in packages/2/node_modules)

In theory you are using npm workspaces to ensure some consistency across packages, therefore ensuring your versions are consistent will mean node_modules is only ever created in the root of your repository

like image 71
Brad Avatar answered Oct 19 '25 05:10

Brad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!