|
| 1 | +--- |
| 2 | +title: Workspace |
| 3 | +description: Use Fumadocs MDX in multiple workspace. |
| 4 | +--- |
| 5 | + |
| 6 | +## Overview |
| 7 | + |
| 8 | +**Workspace** in Fumadocs MDX, refers to an independent project with its own config and content. |
| 9 | + |
| 10 | +<Files> |
| 11 | + <Folder name="my-workspace" defaultOpen> |
| 12 | + <Folder name="content/docs" defaultOpen> |
| 13 | + <File name="index.mdx" /> |
| 14 | + <File name="test.mdx" /> |
| 15 | + </Folder> |
| 16 | + <File name="source.config.ts" /> |
| 17 | + </Folder> |
| 18 | + <Folder name="content/docs" defaultOpen> |
| 19 | + <File name="welcome.mdx" /> |
| 20 | + </Folder> |
| 21 | + <File name="source.config.ts" /> |
| 22 | +</Files> |
| 23 | + |
| 24 | +<Callout title="Good to Know"> |
| 25 | + Fumadocs MDX Workspace is not limited to the traditional meaning of workspace |
| 26 | + in package managers. |
| 27 | + |
| 28 | +They do not need to have its own `package.json`, only a config file is needed. |
| 29 | + |
| 30 | +</Callout> |
| 31 | + |
| 32 | +To define a workspace, add: |
| 33 | + |
| 34 | +```ts title="source.config.ts" |
| 35 | +import { defineConfig } from 'fumadocs-mdx/config'; |
| 36 | + |
| 37 | +export default defineConfig({ |
| 38 | + workspaces: { |
| 39 | + 'my-workspace': { |
| 40 | + dir: 'my-workspace', |
| 41 | + config: await import('./my-workspace/source.config.ts'), |
| 42 | + }, |
| 43 | + }, |
| 44 | +}); |
| 45 | +``` |
| 46 | + |
| 47 | +When writing content in a workspace, note that: |
| 48 | + |
| 49 | +- `cwd` refers to the **current workspace directory**. |
| 50 | +- configs will not inherit, workspaces are always independent. |
| 51 | + |
| 52 | +By running dev or build server, you should see collection entries from all workspaces to be generated. |
| 53 | + |
| 54 | +### Accessing Collections |
| 55 | + |
| 56 | +You can access the generated files of a workspace at `.source/{workspace}/*`. For example: |
| 57 | + |
| 58 | +```ts title="lib/source.ts" |
| 59 | +import { docs } from 'fumadocs-mdx:collections/my-workspace/server'; |
| 60 | +``` |
| 61 | + |
| 62 | +> The output location of root workspace is not changed. |
| 63 | +
|
| 64 | +To integrate multiple sources in Fumadocs, use [`multiple`](/docs/headless/source-api/source#multiple-sources): |
| 65 | + |
| 66 | +```ts title="lib/source.ts" |
| 67 | +import { loader, multiple } from 'fumadocs-core/source'; |
| 68 | +import { docs } from 'fumadocs-mdx:collections/server'; |
| 69 | +import * as MyWorkspace from 'fumadocs-mdx:collections/my-workspace/server'; |
| 70 | + |
| 71 | +export const source = loader( |
| 72 | + multiple({ |
| 73 | + root: docs.toFumadocsSource(), |
| 74 | + 'my-workspace': MyWorkspace.docs.toFumadocsSource(), |
| 75 | + }), |
| 76 | + { |
| 77 | + baseUrl: '/docs', |
| 78 | + }, |
| 79 | +); |
| 80 | +``` |
| 81 | + |
| 82 | +## When to Use |
| 83 | + |
| 84 | +In some setups, you might have multiple Fumadocs MDX configs with their own content directory. |
| 85 | + |
| 86 | +With workspaces, you can integrate them into one Fumadocs MDX config, and access all collections of each workspace. |
| 87 | + |
| 88 | +This is cruial for use cases like storing content across multiple repos, a simpified setup would be: |
| 89 | + |
| 90 | +- let your main docs repo be $A$, and other repos be $T_n$ |
| 91 | +- for each repo $T_n$: |
| 92 | + - $T_n$ has $A$ as a git submodule. |
| 93 | + - $T_n$ defines its own config `source.config.ts` and work independently. |
| 94 | + - when a commit is made to the content in $T_n$, it triggers a GitHub action (or CI), which creates a new deployment on $A$. |
| 95 | +- when a deployment is triggered on $A$: |
| 96 | + - Fumadocs MDX handles each $T_n$ as a workspace. |
| 97 | + - each workspace generates its own collection entries, e.g. `fumadocs-mdx:collections/{repo}/server`. |
| 98 | + - Fumadocs `loader()` integrate multiple sources into one. |
0 commit comments