Monorepos with Lerna.js
What
Why
Who
How
MONOREPOS
What
What
Monorepo
A single repository holding the code of multiple projects .
What
What
Lerna.js
A tool that helps you manage multi-package Monorepos with Git and npm
Created by Babel contributors to help them manage 100+ babel packages.
What
Why
Why should you monorepo?
- Manage many apps in a single repo
- Share libraries across apps
- Build each app separately
- Test apps together
-
Teams collaborate more efficiently.
What
Why
Example use case
-
React Web app A - website
-
React Web app B - chrome extension
-
React native Mobile app
-
Shared view components
-
Style guide app
-
Graphical assets library
-
Utilities ( validators / parsers / middleware… )
-
Microservices
What
Why
Why should you lerna?
- Shared node_modules for multiple apps
- automatic "npm link"
- automatic version bumping
- semantic versioning hints
- other utilities
- open source
What
Who
Who's using Lerna?
What
How
How to Lerna?
npm install -g lerna
git init my-mono-repo && cd my-mono-repo
lerna init
Getting Started
What
How
How to`s
cli commands, guides & docs
What
How
Workflow
-
init
-
bootstrap
-
commit
-
publish
What
How
lerna init
Creates a new Lerna repo or upgrade an existing repo to the current version of Lerna.
lerna init -i
What
How
Use yarn workspaces
lerna.json
{
"packages": [
"packages/*"
],
"version": "independent",
"npmClient": "yarn",
"useWorkspaces": true
}
{
"name": "root",
"private": true,
"devDependencies": {
"lerna": "^3.13.4"
},
"workspaces": ["packages/*"]
}
package.json
What
How
lerna bootstrap
Installing all packages dependencies and linking any cross-dependencies.
lerna bootstrap
What
How
lerna publish
Creates a new release of the packages that have been updated. Prompts for a new version and updates all the packages on git and npm.
lerna publish
What
How
lerna import
Transforms an external repository to a monorepo package.
lerna import <path-to-external-repository>
What
How
lerna run
Runs an npm script in each package that contains that script.
lerna run <npm script> -- [...args]
lerna run build
lerna run start --scope "foo-*"
lerna run watch --parallel --stream
What
How
lerna exec
Runs a shell command in each package.
lerna exec -- <shell command>
lerna exec -- ls
lerna exec -- rm rf ./node_modules
What
How
lerna clean
Remove the node_modules directory from all packages.
lerna clean [--yes] [--scope] [--ignore]
# Equivalent to:
$ lerna exec -- rm -rf ./node_modules
Monorepos wth Lerna.js
By Yariv Gilad
Monorepos wth Lerna.js
- 853