-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sylwia/adds monorepo support section #54
base: main
Are you sure you want to change the base?
Changes from all commits
bfb68cb
a2ad4f8
e30fc7f
ed13d4b
9a9b6a2
b3f1a74
9aba289
480cd22
ea80e3b
a484f75
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
You can also see demos for each of the package managers in this [monorepo demo collection](https://stackblitz.com/@d3lm/collections/workspaces). | ||
|
||
### npm | ||
|
||
Your project repository may look like this: | ||
|
||
``` | ||
workspace-project | ||
├─ packages | ||
│ ├─ backend | ||
│ │ ├─ package.json | ||
│ │ └─ index.js | ||
│ ├─ frontend | ||
│ │ ├─ package.json | ||
│ │ └─ index.js | ||
│ └─ common | ||
│ ├─ package.json | ||
│ └─ index.js | ||
└─ package.json | ||
``` | ||
|
||
To define a workspace, add the `workspaces` field to the `package.json`: | ||
|
||
```json | ||
"workspaces": [ | ||
"packages/*" | ||
], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this page, some of our examples of fragments from My vote would be for no trailing comma, because:
It's hard to predict where users will need to add commas exactly to have valid JSON, so I'd rather let users be responsible for that. But I’m fine with always including the trailing comma if we think that's better (as long as we're consistent). |
||
``` | ||
|
||
This refers to every sub-directory inside `packages` which contains a `package.json`. | ||
|
||
Check the [npm documentation](https://docs.npmjs.com/cli/v7/using-npm/workspaces) for more information or [this npm-based monorepo demo](https://stackblitz.com/edit/node-4cygsf?file=README.md) for reference. | ||
|
||
### pnpm | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
To configure a workspace with pnpm, add the `pnpm-workspace.yaml` file to the root of the project: | ||
|
||
```yaml | ||
packages: | ||
- 'packages/*' | ||
``` | ||
|
||
Next, add a package from the workspace as a dependency to another package. In the example below we define `frontend` as dependent on `common`: | ||
|
||
```json | ||
"dependencies": { | ||
"common": "workspace:^1.0.0" | ||
} | ||
``` | ||
|
||
The `workspace:` protocol ensures the correct package from the workspace is used. However, this is not required because, by default, pnpm will link packages from the workspace if the available packages match the declared ranges. | ||
|
||
Check [pnpm documentation](https://pnpm.io/workspaces) for more information or [this pnpm-based monorepo demo](https://stackblitz.com/edit/node-gw1rvh?file=README.md) for reference. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally the two example projects we link from this page could have:
|
||
|
||
|
||
### Yarn | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we specify that we support Yarn v1 only? I'm not sure if Yarn Berry (v2+) workspaces are exactly the same or different. |
||
|
||
To define a workspace with yarn, add the `workspaces` field to our `package.json`: | ||
|
||
``` | ||
"workspaces": [ | ||
"packages/*" | ||
], | ||
``` | ||
|
||
This refers to every sub-directory inside `packages` which contains a `package.json`. | ||
|
||
:::info | ||
Note that a yarn workspace looks somewhat identical to an npm workspace. For the most part that's true, but yarn also adds useful features such as [`nohoist`](https://classic.yarnpkg.com/blog/2018/02/15/nohoist). | ||
::: |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
title: Monorepo support in WebContainers | ||
--- | ||
|
||
# {{ $frontmatter.title }} | ||
|
||
|
||
WebContainers support workspaces. Follow a walkthrough below to get your monorepo running in WebContainers. <!-- @include: ../../parts/monorepo-support.md --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not fond of having a large content fragment that we include in several places, to be honest. I like having a single URL where content leaves. Might be better for SEO (avoids the risk of a search engine classing a page as duplicate content and removing it from its index), and for search (you don't get two competing results for the same information).