lerna中使用workspace

在lerna中启用workspace:

1,lerna.json中lerna的设置

{
  ...
  "npmClient": "yarn",
  "useWorkspaces": true,
  ...
}

lerna与yarn workspace有很好的相性,设置useWorkspaces等价于使用bootstrap命令的--use-workspaces选项

2,根目录下的package.json

{
  ...
  "private": true,
  "workspaces": [
    "packages/*"
  ],
  ...
}

"private": true是必须的,workspaces为工作空间中所包含的项目路径,

注意: 若开启了workspace功能,则lerna会将package.jsonworkspaces中所设置的项目路径作为lerna packages的路径,而不会使用lerna.json中的packages值。

详解:

Integrating with Lerna

Do Yarn Workspaces make Lerna obsolete?

Not at all. Yarn Workspaces are easily integrated with Lerna.

Lerna provides a lot more than just bootstrapping a project and it has a community of users around it that have fine-tuned Lerna for their needs.

Starting with Lerna 2.0.0, when you pass the flag --use-workspaces when running Lerna commands, it will use Yarn to bootstrap the project and also it will use package.json/workspacesfield to find the packages instead of lerna.json/packages.

This is how Lerna is configured for Jest:

{
  "lerna": "2.0.0",
  "npmClient": "yarn",
  "useWorkspaces": true
}

Jest relies on Yarn to bootstrap the project, and on Lerna for running the publish command(s).

What is next?

Yarn Workspaces is the first step of what a package manager could do for managing monorepos as they become a more common solution to code sharing.

At the same time we don’t want to put all the possible monorepo features into Yarn. We want to keep Yarn focused and lean, and this means that Yarn and projects like Lerna will continue working together.

Our next goal is to finalize Yarn 1.0, which is meant to summarize the work we have done on Yarn over the past year, and recognizing how reliable Yarn has become. We’ll also share our thoughts on what we’d like to build next for Yarn then.

Stay tuned.

 

参考:https://juejin.im/entry/5c26d0db6fb9a04a0e2d45a4

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值