文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
lerna
官网: https://github.com/lerna/lerna/
Lerna 是一种工具,针对 使用 git 和 npm 管理多软件包代码仓库的工作流程进行优化。
安装
# 安装到全局
$ npm install --global lerna
# 创建 git 仓库
$ git init lerna-repo && cd lerna-repo
# 将 git 仓库转化成 lerna 仓库,会生成如下仓库结构,包括 lerna.json, package.json
$ lerna init
lerna 代码仓库结构
lerna-repo/
packages/
package.json
lerna.json
lerna.json 示例
{
"version": "1.1.3",
"npmClient": "npm",
"command": {
"publish": {
"ignoreChanges": ["ignored-file", "*.md"],
"message": "chore(release): publish",
"registry": "https://npm.pkg.github.com"
},
"bootstrap": {
"ignore": "component-*",
"npmClientArgs": ["--no-package-lock"]
}
},
"packages": ["packages/*"]
}
常用命令
$ lerna --help
Usage: cli.js <command> [options]
命令:
cli.js add <pkg> [globs..] Add a single dependency to matched packages
cli.js bootstrap Link local packages together and install remaining package dependencies
cli.js changed List local packages that have changed since the last tagged release [aliases: updated]
cli.js clean Remove the node_modules directory from all packages
cli.js create <name> [loc] Create a new lerna-managed package
cli.js diff [pkgName] Diff all packages or a single package since the last release
cli.js exec [cmd] [args..] Execute an arbitrary command in each package
cli.js import <dir> Import a package into the monorepo with commit history
cli.js info Prints debugging information about the local environment
cli.js init Create a new Lerna repo or upgrade an existing repo to the current version of Lerna.
cli.js link Symlink together all packages that are dependencies of each other
cli.js list List local packages [aliases: ls, la, ll]
cli.js publish [bump] Publish packages in the current project.
cli.js run <script> Run an npm script in each package that contains that script
cli.js version [bump] Bump version of packages changed since the last release.
Global Options:
--loglevel What level of logs to report. [字符串] [默认值: info]
--concurrency How many processes to use when lerna parallelizes tasks. [数字] [默认值: 12]
--reject-cycles Fail if a cycle is detected among dependencies. [布尔]
--no-progress Disable progress bars. (Always off in CI) [布尔]
--no-sort Do not sort packages topologically (dependencies before dependents). [布尔]
--max-buffer Set max-buffer (in bytes) for subcommand execution [数字]
-h, --help 显示帮助信息 [布尔]
-v, --version 显示版本号 [布尔]
When a command fails, all logs are written to lerna-debug.log in the current working directory.
For more information, find our manual at https://github.com/lerna/lerna
发布 lerna publish
lerna 有两种工作模式,如下
- Independent mode 独立开发。lerna 会配合
Git
,检查文件变动,只发布有改动的 packge。 - Fixed/Locked mode 默认模式。把工程当作一个整体来对待。每次发布 packges,都是全量发布,无论是否修改。
lerna 最佳实践
为了能够使 lerna 发挥最大的作用,根据这段时间使用 lerna
的经验,总结出一个最佳实践。下面是一些特性。
- 采用 Independent 模式
- 根据
Git
提交信息,自动生成 changelog - eslint 规则检查
- prettier 自动格式化代码
- 提交代码,代码检查 hook
- 遵循 semver 版本规范
本章参考
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论