This project represents a minimal example that uses Lerna to structure a Typescript monorepo with multiple packages and some dependencies between the packages. Shown below is the dependency graph between the packages in this project:
npx lerna run build
to build all packages and their dependencies.npx lerna run build --scope @js-monorepo/useful
to build just thepackages/useful
package.
This is mostly needed when you are making changes locally and would like to have a fast development loop to test the results of your changes.
If you would like to establish a dependency between packages within this monorepo, you can add the dependency in the dependent package's package.json
with a *
as the version specification.
- Specifying
*
instructs Lerna that it should call thebuild
script of the dependency before calling thebuild
script of the dependning application.
If you would like to establish a dependency between packages within this monorepo and an external client application that consumes these packages,
- Run
npm link
at the root of the specific package you are making code changes in. - Run
npx lerna run build --scope <package>
to build that specific package. - In the client application, run
npm link <package> --force
to ensure that thepackage.json
of the client application is updated with afile:
link to the dependency. This effectively creates a symlink in thenode_modules
of the client application to the local dependency.
Having done this setup, this is what the development cycle looks like moving forward:
- Make code change
- Rebuild specific package
- Rebuild client application.