Skip to content

Commit

Permalink
docs: add types for theme config (#3117)
Browse files Browse the repository at this point in the history
* docs: add types for theme config

* chore: missing {}
  • Loading branch information
userquin authored Oct 21, 2023
1 parent 6cf1de5 commit 71bed58
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
18 changes: 18 additions & 0 deletions docs/guide/extending-default-theme.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export default {
// .vitepress/theme/index.js
import DefaultTheme from 'vitepress/theme'

/** @type {import('vitepress').Theme} */
export default {
extends: DefaultTheme,
enhanceApp(ctx) {
Expand All @@ -107,6 +108,23 @@ export default {
}
```

If you're using TypeScript:
```ts
// .vitepress/theme/index.ts
import type { Theme } from 'vitepress'
import DefaultTheme from 'vitepress/theme'

export default {
// ...
async enhanceApp({ app }) {
if (!import.meta.env.SSR) {
const plugin = await import('plugin-that-access-window-on-import')
app.use(plugin)
}
}
} satisfies Theme
```

Since we are using Vite, you can also leverage Vite's [glob import feature](https://vitejs.dev/guide/features.html#glob-import) to auto register a directory of components.

## Layout Slots
Expand Down
17 changes: 17 additions & 0 deletions docs/guide/ssr-compat.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Since [`Theme.enhanceApp`](./custom-theme#theme-interface) can be async, you can
```js
// .vitepress/theme/index.js
/** @type {import('vitepress').Theme} */
export default {
// ...
async enhanceApp({ app }) {
Expand All @@ -63,6 +64,22 @@ export default {
}
```
If you're using TypeScript:
```ts
// .vitepress/theme/index.ts
import type { Theme } from 'vitepress'

export default {
// ...
async enhanceApp({ app }) {
if (!import.meta.env.SSR) {
const plugin = await import('plugin-that-access-window-on-import')
app.use(plugin)
}
}
} satisfies Theme
```
### `defineClientComponent`
VitePress provides a convenience helper for importing Vue components that access browser APIs on import.
Expand Down

0 comments on commit 71bed58

Please sign in to comment.