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

你可能感兴趣的:(node)