Install Dependencies for Specific Packages in a Monorepo

Share this video with your friends

Social Share Links

Send Tweet
Published 2 years ago
Updated 2 years ago

We can install a dependency inside a monorepo by running npm install, then the name of the dependency, in our case, it’s going to be Lodash. But, we are going to add different flags to that.

If we use the -w flag, we would have to specify in what package we want to install Lodash. We will do this for monorepo/utils. We could also use the -ws flag to install Lodash across all the packages in the monorepo. We can also use -W in uppercase to install Lodash in the root of the project.

Instructor: [0:00] We would install an npm package inside a package of a monorepo by running npm install, then the name of the package. Then we add the -w flag. We specify where we want it. In this case, we want to install Lodash inside the utils package. Let's check out the package.json file inside the utils folder. There you have it. We have Lodash.

[0:23] If we run git status, we'll see that we have modified the package.json file inside the utils package. We could install Lodash across all the packages in the monorepo by adding the -ws flag.

[0:38] Now, let's run git status to see what has changed. Yes, the app's package-lock.json file has changed. Same for the dashboard and same for the utils.

[0:48] We could also install one dependency in the root of the monorepo by running npm install, the name of the dependency, then we use the -W, this time with uppercase. Let's run git status to see what has changed. This time, we modified the package.json file that is in the root of the project.

[1:08] To recap, we can install a dependency inside a monorepo by running npm install, then the name of the dependency, in this case is going to be Lodash. We are going to add different flags.

[1:20] If we use the -w flag, we would have to specify in what package we want to install Lodash. In this case, it could be monorepo/utils. We could also use the -ws flag to install Lodash across all the packages in the monorepo. We can also use -W in uppercase to install Lodash in the root of the project.