使用 yarn workspaces 和 lerna 优先构建顺序
Prioritize build order with yarn workspaces and lerna
我在使用 yarn workspaces
和 lerna
的单一存储库中有这个大型打字稿项目,架构如下:
repo
├── API
│ └── (GraphQL API)
├── Apps
│ └── (Front-end React Apps)
├── Libs
│ └── (Shared libraries)
└── Services
└── (Back-end Services)
我的 package.json
看起来像:
{
...
"workspaces": [
"API/**/*",
"Apps/**/*",
"Libs/**/*",
"Services/**/*",
],
"scripts": {
"bootstrap": "lerna bootstrap",
"build": "lerna run build"
}
...
}
我的 lerna.json
看起来像:
{
"lerna": "2.11.0",
"npmClient": "yarn",
"useWorkspaces": true,
"workspaces": [
"Libs/**/*",
"API/**/*",
"Apps/**/*",
"Services/**/*"
],
"version": "1.0.0"
}
现在我需要在 Apps
和 Services
之前构建所有共享的 Libs
,因为它们依赖于它。但是当我 运行 yarn build
并且它触发 lerna run build
时,它似乎以随机(?)顺序触发 build
过程,所以它无法构建,因为库 "don't exist, yet".
有没有办法设置 lerna
如何触发构建的顺序?
到目前为止 lerna
没有优先级。
虽然这是我目前在几个项目中所做的:
"scripts": {
...
"build": "lerna run build --ignore=libs-*",
"prebuild": "lerna run build --scope=libs-*"
...
}
注意:prebuild
将自动 运行,因此您无需显式调用它
这里需要注意的是,您需要在所有 Libs
包名称前加上 libs-module-name
之类的前缀,如上例所示,或者可能使用 @my-org-libs/module-name
之类的范围,并使用 [= 调用它们16=] 代替。
另一个解决方案是在 prebuild
中使用多个 --scope=package-name --scope=package-name-2
参数显式调用每个 Libs
包。但是如果你在 Libs
.
下有很多模块,那可能很快就会变得丑陋
我在使用 yarn workspaces
和 lerna
的单一存储库中有这个大型打字稿项目,架构如下:
repo
├── API
│ └── (GraphQL API)
├── Apps
│ └── (Front-end React Apps)
├── Libs
│ └── (Shared libraries)
└── Services
└── (Back-end Services)
我的 package.json
看起来像:
{
...
"workspaces": [
"API/**/*",
"Apps/**/*",
"Libs/**/*",
"Services/**/*",
],
"scripts": {
"bootstrap": "lerna bootstrap",
"build": "lerna run build"
}
...
}
我的 lerna.json
看起来像:
{
"lerna": "2.11.0",
"npmClient": "yarn",
"useWorkspaces": true,
"workspaces": [
"Libs/**/*",
"API/**/*",
"Apps/**/*",
"Services/**/*"
],
"version": "1.0.0"
}
现在我需要在 Apps
和 Services
之前构建所有共享的 Libs
,因为它们依赖于它。但是当我 运行 yarn build
并且它触发 lerna run build
时,它似乎以随机(?)顺序触发 build
过程,所以它无法构建,因为库 "don't exist, yet".
有没有办法设置 lerna
如何触发构建的顺序?
到目前为止 lerna
没有优先级。
虽然这是我目前在几个项目中所做的:
"scripts": {
...
"build": "lerna run build --ignore=libs-*",
"prebuild": "lerna run build --scope=libs-*"
...
}
注意:prebuild
将自动 运行,因此您无需显式调用它
这里需要注意的是,您需要在所有 Libs
包名称前加上 libs-module-name
之类的前缀,如上例所示,或者可能使用 @my-org-libs/module-name
之类的范围,并使用 [= 调用它们16=] 代替。
另一个解决方案是在 prebuild
中使用多个 --scope=package-name --scope=package-name-2
参数显式调用每个 Libs
包。但是如果你在 Libs
.