Skip to content

Commit 22cddb8

Browse files
Max Blackowlstronaut
authored andcommitted
docs: add workspace dependencies example to workspaces
1 parent 17e154c commit 22cddb8

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

docs/lib/content/using-npm/workspaces.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,26 @@ If you want to add a dependency named `abbrev` from the registry as a dependency
8686
npm install abbrev -w a
8787
```
8888

89+
**Adding a workspace as a dependency of another workspace:**
90+
91+
If you want to add workspace **b** as a dependency of workspace **a**, you can use the workspace protocol in the dependency specifier:
92+
93+
```
94+
npm install b@workspace:* -w a
95+
```
96+
97+
This will add an entry to workspace **a**'s `package.json` like:
98+
99+
```json
100+
{
101+
"dependencies": {
102+
"b": "workspace:*"
103+
}
104+
}
105+
```
106+
107+
The `workspace:` protocol tells npm to link to the local workspace rather than fetching from the registry. The `*` version means it will use whatever version is defined in workspace **b**'s `package.json`.
108+
89109
Note: other installing commands such as `uninstall`, `ci`, etc will also respect the provided `workspace` configuration.
90110

91111
### Using workspaces

0 commit comments

Comments
 (0)