使用 lerna 和 yarn 构建 monorepo 项目,核心思想是 用yarn来处理依赖问题,用lerna来处理发布问题。
When coupled together, Lerna and Yarn Workspaces can ease and optimize the management of working with multi-package repositories.
Lerna makes versioning and publishing packages to an NPM Org a painless experience by providing helpful utility commands for handling the execution of tasks across multiple packages.
Yarn Workspaces manages our dependencies. Rather than having multiple node_modules directories, it intelligently optimizes the installing of dependencies together and allows for the cross-linking of dependencies in a monorepo. Yarn Workspaces provide tools, like Lerna, the low-level primitives it needs to manage multi-package repositories.
https://github.com/aggresss/hello-js
lerna init
# lerna.json
"npmClient": "yarn",
"useWorkspaces": true,
# package.json
"workspaces": ["packages/*"]
lerna create @hello-js/saysomething
lerna create @hello-js/sayhelloworld
lerna add @hello-js/saysomething --scope @hello-js/sayhelloworld
yarn workspace @hello-js/sayhelloworld start
yarn run demo:start
参考文档
- lerna+yarn workspace+monorepo项目的最佳实践
- 基于 Lerna 管理 packages 的 Monorepo 项目最佳实践
- JavaScript extensions for VS Code
- A Beginner’s Guide to Lerna with Yarn Workspaces
- https://lerna.js.org/
- https://yarnpkg.com/lang/en/
- https://docs.npmjs.com/
- https://webpack.js.org/concepts/
- 项目开发之package.json
- Why Lerna and Yarn Workspaces is a Perfect Match for Building Mono-Repos – A Close Look at Features and Performance