diff options
author | 2023-09-22 16:42:17 -0700 | |
---|---|---|
committer | 2023-09-22 16:42:23 -0700 | |
commit | feefaf00d799e152e1c816e7cd8c8beb70c7f074 (patch) | |
tree | a080977c6b1cf1af3214e7113b3fb4bd25dd7f87 | |
parent | 25e69c71e70ac8a0a88f9cf15b4057bd7b2a633a (diff) | |
download | bun-feefaf00d799e152e1c816e7cd8c8beb70c7f074.tar.gz bun-feefaf00d799e152e1c816e7cd8c8beb70c7f074.tar.zst bun-feefaf00d799e152e1c816e7cd8c8beb70c7f074.zip |
Update workspaces.md
-rw-r--r-- | docs/install/workspaces.md | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/docs/install/workspaces.md b/docs/install/workspaces.md index 608efb537..079ef7dd4 100644 --- a/docs/install/workspaces.md +++ b/docs/install/workspaces.md @@ -1,6 +1,30 @@ Bun supports [`workspaces`](https://docs.npmjs.com/cli/v9/using-npm/workspaces?v=true#description) in `package.json`. Workspaces make it easy to develop complex software as a _monorepo_ consisting of several independent packages. -To try it, specify a list of sub-packages in the `workspaces` field of your `package.json`; it's conventional to place these sub-packages in a directory called `packages`. +It's common for a monorepo to have the following structure: + +``` +tree +<root> +├── README.md +├── bun.lockb +├── package.json +├── tsconfig.json +└── packages + ├── pkg-a + │ ├── index.ts + │ ├── package.json + │ └── tsconfig.json + ├── pkg-b + │ ├── index.ts + │ ├── package.json + │ └── tsconfig.json + └── pkg-c + ├── index.ts + ├── package.json + └── tsconfig.json +``` + +In the root `package.json`, the `"workspaces"` key is used to indicate which subdirectories should be considered packages/workspaces within the monorepo. It conventional to place all the workspace in a directory called `packages`. ```json { @@ -17,7 +41,7 @@ To try it, specify a list of sub-packages in the `workspaces` field of your `pac **Glob support** — Bun supports simple `<directory>/*` globs in `"workspaces"`. Full glob syntax (e.g. `**` and `?`) is not yet supported. {% /callout %} -When referencing other packages in the monorepo, use `"workspace:*"` as the version field in your `package.json`. +Each workspace has it's own `package.json` When referencing other packages in the monorepo, use `"workspace:*"` as the version field in your `package.json`. ```json { @@ -35,7 +59,7 @@ When referencing other packages in the monorepo, use `"workspace:*"` as the vers Workspaces have a couple major benefits. -- **Code can be split into logical parts.** If one package relies on another, you can simply add it as a dependency with `bun add`. If package `b` depends on `a`, `bun install` will symlink your local `packages/a` directory into the `node_modules` folder of `b`, instead of trying to download it from the npm registry. +- **Code can be split into logical parts.** If one package relies on another, you can simply add it as a dependency in `package.json`. If package `b` depends on `a`, `bun install` will install your local `packages/a` directory into `node_modules` instead of downloading it from the npm registry. - **Dependencies can be de-duplicated.** If `a` and `b` share a common dependency, it will be _hoisted_ to the root `node_modules` directory. This reduces redundant disk usage and minimizes "dependency hell" issues associated with having multiple versions of a package installed simultaneously. {% callout %} |