問題描述
將 monorepo 包放在包文件夾下是一種約定,還是 yarn 工作區期望這樣? (Is putting monorepo packages under a package folder a convention, or do yarn workspace expect that?)
我的 monorepo 文件夾結構看起來像這樣,但是我沒有跨應用程序導入來為 yarn 工作區工作,也就是說,我無法從 shared
導入到 app1 或
app2
.
./
app1
app2
shared
server
package.json
我見過的幾乎所有其他工作區都包含一個 packages 文件夾,這是必需的還是只是約定?在這種情況下,我的文件夾結構如下所示:
./
packages
app1
app2
shared
server
package.json
我是否需要重構工作區才能正常工作?
參考解法
方法 1:
It's just a convention. You need to list your workspaces
in package.json
:
"workspaces": [
"app1",
"app2",
"shared",
"server"
],
The convention let's you use a glob (and presumably streamlines some other npm
/yarn
commands that you want to run across all packages):
"workspaces": ["packages/*"],
(by Gabriel Petersson、charles‑allen)
參考文件