说明
Lerna is a tool that optimizes the workflow around managing multi-package repositories with git and npm.
对于维护多个 package
来说,都会遇到一个选择,是选择 mono-repo
还是 multi-repo
。multi-repo
一个模块(module)一个仓库(repository),而 mono-repo
是所有模块整合在一个仓库,语义来源 (opens new window)。
使用
lerna
初始化分为两种模式:fix
(默认,锁定模式,项目内的所有 package 共用版本号)、independent
(独立模式,每个 package
拥有独立版本号)。个人认为大部分情况下都应该使用独立模式,即每个 package
都有自己的版本号。
# 安装
npm i lerna -g
# git
git init lerna-repo && cd lerna-repo
# lerna
lerna init [--independent] # 生成下方文件夹
#lerna-repo
#├── lerna.json
#├── package.json
#└── packages
# 创建 packages
lerna create pkg-1 -y
lerna create pkg-2 -y
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
依赖
1. 工具依赖
对于 eslint
、commit-lint
等工具依赖,可以直接使用 yarn
或 npm
安装到顶层。
2. package 依赖
针对 package 的依赖可以交由 lerna
安装。
所有 packages
lerna add module1
1单独 package
lerna add module1 packages/pkg-1
1
更多命令
lerna publish
(opens new window)lerna version
(opens new window)lerna bootstrap
(opens new window)lerna list
(opens new window)lerna changed
(opens new window)lerna diff
(opens new window)lerna exec
(opens new window)lerna run
(opens new window)lerna init
(opens new window)lerna add
(opens new window)lerna clean
(opens new window)lerna import
(opens new window)lerna link
(opens new window)lerna create
(opens new window)lerna info
(opens new window)