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.
What's the use case for installing libraries in the root package.json?
@Yujing great question.
I’d recommend installing as few dependencies as possible in the root package.json file. The ones that I can think of right now are, concurrently, Turborepo and Husky. The reason for those libraries to exist in your monorepo is to help you “manage” your project; for instance, you’d want to use concurrently to run all your scripts or Husky to create git-hooks that affect all your projects.
My default approach is to install all the dependencies you need for a project inside the project itself; for example, you’ll want the blog
and the dashboard
projects to have their version of React installed; if you do that, you can easily update one project independently without much trouble. Another benefit of this approach is that you know exactly what dependencies Your project uses.
@Yujing, feel free to ask again if you still have questions! 👍
I can't find any of these commands or flags under npm docs. Where do you learn this stuff?