[Case Study] How to select node modules for an individual app deployment within a multi-app monorepo?
See original GitHub issueHi, firstly thanks for the great work at Yarn.
As I understand, authors of Yarn V2 has mentioned a lot of times that you have no intentions to support nohoist
in V2.
I wonder if there is an alternative way to support multi-app monorepo deployment, especially on node module management?
Say, a monorepo structure like 👇
-
package.json
-
apps
- web-service-a
- package.json
- Dockerfile
- search-service-b
- package.json
- Dockerfile
- admin-service-c
- package.json
- Dockerfile
- web-service-a
-
shared-modules
- lib-a
- package.json
- lib-b
- package.json
- lib-a
As a typical multi-app monorepo pattern, each of the apps is an individual deployable HTTP server. Monorepo benefits us for cross-API type checking, lib sharing, deployment order management, etc. Having this, an essential requirement is to deploy one app like web-service-a
with only its required node modules.
Previously, we were able to use Yarn V1 "nohoist": ["**"]
to achieve node module separation during Docker image build-time.
Describe the goal of the investigation
Investigate if Yarn V2 suits multi-app monorepos.
Investigation report
Ideally, we would want Yarn V2 to be able to separate or assist us to separate node modules for individual packages. We don’t mind using hoisting as it is at development-time. But for production deployment, we will need to avoid bloat node modules across apps and minimize Docker images’ size.
I could be missing something from the doc. Any clues, corrections, or future plans sharing will be appreciated. Thanks in advanced =]
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
@ivawzh Yarn 2 has much better way to support multi-app workflow than fragile and confusing
nohoist
. You can useyarn workspaces focus
command insideapps/web-service-a
when you are going to install it inside Docker. This will installapps/web-service-a
dependencies and shared modules dependencies it depends on and will NOT installsearch-service-b
andadmin-service-c
dependencies. The subset of installed dependencies will be properly deduplicated and hoisted into rootnode_modules
dir if you are usingnode-modules
linker. This sameyarn workspaces focus
approach works for multi-app pnp projects as well. The relevant docs are here: https://yarnpkg.com/cli/workspaces/focusWhat if I want to remove unrelated workspaces at the same time?