How to setup Yarn-Workspaces correctly

2020-07-22 09:06发布

问题:

my project got the following structure

project-root
- common-modules
    - build-modules
        - packageA
        - packageB
    - packageC
    - packageD
- services
    - packageE -> needs packageA, packageC / devDependency on packageD
    - packageF -> needs packageB, packageC / devDependency on packageD

Each package and the project-root have a package.json with all the defined dependencies and devDependencies.

What is the right way to configure my project with yarn workspaces?

I don't want a single node_modules folder in each package, but one in the project-root.

Setting the package.json in the project-root up with

"workspaces": [
    "common-modules/build-modules/*", 
    "common-modules/packageC",
    "common-modules/packageD",
    "services/*"
]

did not work, because I could not even build packageE since the gulp-script could not require a devDependency.