🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[TOC] ## init ``` npx lerna init # 指定单个包 npx lerna init --packages="packages/*" # 指定多个包 npx lerna init --packages="foo/*" --packages="bar/*" ``` ## run ``` // 跑每个包的 build npx lerna run build // 跑每个包的 test npx lerna run test 执行多个任务 npx lerna run test,build,lint 指定包 npx lerna run test --scope=header ``` ## bootstrap - 会把所有包的依赖安装到根node_modules - 对一个新的仓库可使用 `bootstrap` 代替`npm install` 安装依赖 ``` npx lerna bootstrap ``` - 当我们在一个包含多个子包的代码仓库中新增或更新了某个子包的依赖项时,我们需要运行 lerna bootstrap 命令来更新整个代码仓库中所有子包的依赖项- - 自动处理 Git submodule 和 Yarn workspaces 等 ## list 列表当前的包 ``` > npx lerna list client-sdk ``` ## exec 在每个包中执行命令 格式 ``` lerna exec [cmd] [args..] ``` 示例 ``` $ lerna exec -- < command > [..args] # runs the command in all packages $ lerna exec -- rm -rf ./node_modules $ lerna exec -- protractor conf.js lerna exec --scope my-component -- ls -la ``` ## link - `lerna link` 命令会在当前 Lerna 项目的根目录下查找所有的子包,在子包中运行 `npm install` 时,就会自动从根目录的 `node_modules` 目录中获取共享的依赖包,而不需要重新下载和安装 ``` npx lerna link ``` ## clean 删除所有包的 node_modules ``` npx lerna clean ``` ## changed - 列出下次发版`lerna publish`要更新的包。 - 原理: 需要先git add,git commit 提交。 然后内部会运行`git diff --name-only v版本号`,搜集改动的包,就是下次要发布的。并不是网上人说的所有包都是同一个版全发布。 ``` npx lerna changed ``` ## publish 会打tag,上传git,上传npm。