Lerna is a tool for managing JavaScript projects with multiple packages. It allows you to manage the dependencies of and between packages in your project.
This tutorial shows you how to add dependencies to a single package in a Lerna-managed project.
Lerna Series Overview
- Install Dependencies for a Specific Package
- Publish Release for All Packages
- Replacing the Bootstrap Command
Install Dependency to Specific Package With Lerna
Lerna comes with an add
command to install NPM dependencies in your project’s packages. By default, lerna adds a new dependency to all managed packages.
You can scope the add
command to individual packages using the --scope=<package-name>
flag. This will install a given dependency only to <package-name>
:
lerna add a --scope=b
# add package "a" to multiple packages
lerna add a --scope=b --scope=c --scope=d
Here’s a concrete example installing @supercharge/strings
as a dependency to the @supercharge/session
package:
lerna add @supercharge/strings --scope=@supercharge/session
That’s it! You can now use the added dependency in the related package.
Mentioned Resources
- @supercharge/strings repository on Github
- lerna repository on GitHub