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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With