使用 lerna 和 yarn 构建 monorepo 项目

使用 lerna 和 yarn 构建 monorepo 项目,核心思想是 用yarn来处理依赖问题,用lerna来处理发布问题。

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

参考文档

  1. lerna+yarn workspace+monorepo项目的最佳实践
  2. 基于 Lerna 管理 packages 的 Monorepo 项目最佳实践
  3. JavaScript extensions for VS Code
  4. A Beginner’s Guide to Lerna with Yarn Workspaces
  5. https://lerna.js.org/
  6. https://yarnpkg.com/lang/en/
  7. https://docs.npmjs.com/
  8. https://webpack.js.org/concepts/
  9. 项目开发之package.json
  10. Why Lerna and Yarn Workspaces is a Perfect Match for Building Mono-Repos – A Close Look at Features and Performance
发布了105 篇原创文章 · 获赞 230 · 访问量 36万+

猜你喜欢

转载自blog.csdn.net/aggresss/article/details/102544299