I built a monorepo using Lerna and Yarn workspaces.
Everything works fine but everytime I install a new dependency on a package (let's call him A) using:
yarn add <package_name>
Yarn adds it and then triggers the install
script of all the packages in the monorepo, even the ones that A doesn't rely on.
It there anyway to avoid this? It takes a few moment to install them for no reason at all.
We can also define which package manager Lerna uses, such as npm or yarn. The above command also initializes a package folder where the projects can be located. In the lerna. json file, add the npmClient option to specify yarn as the package manager.
Step 3 — Installing Packages in the Monorepo Lerna can help you manage packages and dependencies across projects within the monorepo. To add a package to your project, use the lerna exec command to execute a shell command: lerna exec npm i lite-server --parallel.
yarn install is used to install all dependencies for a project. The dependencies are retrieved from your project's package. json file, and stored in the yarn.
Try adding to the specific workspace with:-
yarn workspace <workspace_name> add <package_name>
For some docs check here
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