在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.json
中workspaces
中所设置的项目路径作为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/workspaces
field 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.