You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 87f645b
Browse filesBrowse the repository at this point in the historyBrowse files
✨ feat(vite): add official consumer vite extension entry
Support docs.config vite module path and docs.vite.* convention files so
consumers can prepend Vite plugins without pnpm-patching docs-kit. Public
helpers ship from @lobehub/docs-kit/vite-extension.
|`title`|`string`| Required. Site name in `<title>`, OG, llms.txt |
13
+
|`description`|`string`| Required. Site summary |
14
+
|`siteUrl`|`string`| Required. Canonical origin (no trailing slash) for sitemap/OG/canonical |
15
+
|`alias`|`Record<string, string>`| Vite aliases. Map your package name (and `pkg/es`) to `src` so demos import the package but run source |
16
+
|`homePage`|`string`| Path to a module whose default export is the landing page. Missing file = build error |
17
+
|`publicDocs`|`string[]`| Extra `docs/**/*.mdx` guide pages to publish (route = path without `docs/` and extension) |
18
+
|`navSections`|`Record<string, string>`|`{ 'src/foo/Bar/index.mdx': 'Section' }` — only for a page sitting outside its section's folder |
19
+
|`favicons`|`{ icon?, icon16?, icon32?, appleTouchIcon? }`| Hrefs into `public/`; unset keys fall back to lobe-ui's paths, so set all four |
20
+
|`legacyRedirects`|`DocumentationInventory`| Frozen old-URL inventory (lobe-ui's `compatibility.json` from dumi). New sites: omit |
21
+
|`vite`|`string`| Module path for consumer Vite plugins / `{ plugins, optimizeDeps, ssr, apply }`. In-process load (hooks kept). Convention: `docs.vite.*` or `docs.kit-plugins.cjs`. See below. |
22
+
23
+
## Consumer Vite plugins (`vite` / `docs.vite.*`)
24
+
25
+
`docs.config.ts` cannot carry plugin hooks (JSON subprocess). Set `vite: './docs.vite.ts'` or add a root convention file (`docs.vite.ts|mts|mjs|js|cjs`, then legacy `docs.kit-plugins.cjs`). The kit prepends returned plugins before its own.
26
+
27
+
Public helper/types: `@lobehub/docs-kit/vite-extension` (`defineDocsVite`, etc.) — same publish style as `react-router-config`. Do not import `@lobehub/docs-kit/src/…` as an API.
28
+
29
+
Export a plugin, plugin array, `(env) => …` factory, or `{ plugins, optimizeDeps?, ssr?, apply? }`. Guard client-only transforms with `options?.ssr` (or `environment.consumer === 'server'`). Use `apply: 'serve'` only for dev-only hooks; demo transforms needed in the static client build must not set `apply: 'serve'`.
30
+
31
+
docs-kit does not ship or E2E-verify Ink/xterm plugins; consumers own those.
Copy file name to clipboardExpand all lines: AGENTS.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -47,7 +47,7 @@ The user-facing docs are the playground site (`pnpm dev`):
47
47
48
48
## Adding Things
49
49
50
-
-**Config field**: add it to `DocsConfig` / `DocsThemeConfig` in `src/config.ts`; if the browser needs it, it reaches the app through `virtual:lobedocs/site-config` (`ClientSiteConfig`). Values must survive JSON (the config is serialized out of a subprocess); pass functions as a module path, like `stylex`. Add a test, document it in `playground/docs/file-conventions/docs-config.mdx`, and update the `using-docs-kit` reference.
50
+
-**Config field**: add it to `DocsConfig` / `DocsThemeConfig` in `src/config.ts`; if the browser needs it, it reaches the app through `virtual:lobedocs/site-config` (`ClientSiteConfig`). Values must survive JSON (the config is serialized out of a subprocess); pass functions as a module path, like `stylex` or `vite` (consumer Vite plugins). Add a test, document it in `playground/docs/file-conventions/docs-config.mdx`, and update the `using-docs-kit` reference.
51
51
-**CLI command**: add a handler to `commands` in `src/cli/commands.ts` (usage text is derived from its keys), cover it in `src/cli/commands.test.ts`, and document it in `playground/docs/getting-started/cli.mdx` and the README table.
52
52
-**Docs UI component**: `site/components/<Name>/<Name>.tsx` with a StyleX `style.ts` (named exports only; StyleX longhands such as `backgroundColor`, enforced by ESLint) and a colocated `<Name>.test.tsx`. To expose it in MDX, register it in `site/app/mdx-components.tsx` and update the "only `Demo` and `Api` are global" statements in docs and skills.
53
53
-**Theme or appearance**: providers and the theme bootstrap live in `site/app/providers/`; global styles in `site/styles/`. Colors come from `@lobehub/ui` tokens, not hard-coded values.
Copy file name to clipboardExpand all lines: playground/docs/advanced/react-router.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,4 +36,4 @@ A config you write yourself always wins: the CLI only generates its temporary `r
36
36
37
37
## Stable entry points
38
38
39
-
`@lobehub/docs-kit/react-router-config` and the `lobedocs` CLI are the supported entry points. Other deep imports into the package are not stable yet.
39
+
`@lobehub/docs-kit/react-router-config`, `@lobehub/docs-kit/vite-extension`, and the `lobedocs` CLI are the supported entry points. Other deep imports into the package are not stable yet.
Copy file name to clipboardExpand all lines: playground/docs/file-conventions/docs-config.mdx
+61Lines changed: 61 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -52,6 +52,7 @@ export default {
52
52
|`navSections`|`Record<string, string>`| Section override keyed by MDX source, for a page outside its section's folder |
53
53
|`favicons`|`Record<string, string>`| Favicon hrefs keyed `icon`, `icon16`, `icon32` and `appleTouchIcon`. Unset keys fall back to `/favicon.ico`, `/favicon-16x16.png`, `/favicon-32x32.png` and `/apple-touch-icon.png`, so ship those in `public/` or set all four |
54
54
|`stylex`|`string \| object`| StyleX options, or a path to a module that default-exports them. See [Theme and Appearance](/guide/theming)|
55
+
|`vite`|`string`| Path to a module that default-exports consumer Vite plugins or a `{ plugins, optimizeDeps, ssr, apply }` object. Loaded in-process (hooks preserved). See below. |
55
56
|`legacyRedirects`|`DocumentationInventory`| Frozen inventory of an old dumi site. See [Migrating from dumi](/advanced/migrating-from-dumi)|
56
57
57
58
### atomDirs
@@ -70,6 +71,66 @@ themeConfig: {
70
71
},
71
72
```
72
73
74
+
### vite
75
+
76
+
`docs.config.ts` is JSON-serialized, so Vite plugin hooks cannot live in the config object. Point `vite` at a module instead (same idea as `stylex`), or drop a convention file at the repository root:
-`docs.kit-plugins.cjs` (legacy filename from an unofficial consumer patch; still loaded for drop-in upgrades)
80
+
81
+
The kit loads that module **in-process** from its own `vite.config.ts` and **prepends** the returned plugins ahead of StyleX / MDX / React Router, so `enforce: 'pre'` transforms run first. Use this to swap browser demo modules, add `configureServer` hooks in `lobedocs dev`, or extend `optimizeDeps` / `ssr`.
82
+
83
+
The public helper and types ship from `@lobehub/docs-kit/vite-extension` (same publish pattern as `@lobehub/docs-kit/react-router-config`). Deep imports under `src/` are not a stable API.
84
+
85
+
```ts
86
+
// docs.config.ts — optional when the convention file name is used
// Client-only: skip SSR / prerender so browser-only deps never enter the server bundle.
104
+
if (options?.ssr) returnnull;
105
+
if (!id.includes('/demos/') ||!id.endsWith('.tsx')) returnnull;
106
+
// Replace the browser module; docs-kit still reads the on-disk source for code display.
107
+
returnnull;
108
+
},
109
+
configureServer() {
110
+
// Dev-only middleware / WebSocket — Vite does not run this during `lobedocs build`.
111
+
},
112
+
});
113
+
114
+
exportdefaultdefineDocsVite({
115
+
// Omit `apply` so transforms also run in the client build. Use `apply: 'serve'` only for
116
+
// hooks that must not exist in build/prerender at all (for example live WebSockets).
117
+
// Do not use `apply: 'serve'` for demo transforms that the static site still needs.
118
+
optimizeDeps: {
119
+
// List browser-only packages your plugin introduces, when needed.
120
+
},
121
+
ssr: {
122
+
// Keep those same packages external to the SSR bundle when needed.
123
+
},
124
+
plugins: [demoBrowserPlugin()],
125
+
});
126
+
```
127
+
128
+
A default export may also be a single plugin, a plugin array, or a factory `(env) => …` that receives Vite's `ConfigEnv` (`command`, `mode`, `isSsrBuild`, …). Zero-arg factories (common in `.cjs` hooks) still work.
129
+
130
+
docs-kit only provides this extension entry and the load/order/`apply` semantics above. It does **not** ship or end-to-end verify any particular Ink / xterm consumer plugin — that remains in the consuming repo.
131
+
132
+
Restart `lobedocs dev` after changing the module path in `docs.config.ts`; Vite still hot-reloads the plugin module once loaded.
0 commit comments