Custom Themes
Building custom themes from scratch with the theme interface, Layout component, and enhanceApp
Theme Entry
// .vitepress/theme/index.ts
import Layout from './Layout.vue'
export default {
Layout,
enhanceApp({ app, router, siteData }) {
// Register global components, plugins, etc.
}
}Theme Interface
interface Theme {
// Required: Root layout component
Layout: Component
// Optional: Enhance Vue app instance
enhanceApp?: (ctx: EnhanceAppContext) => Awaitable<void>
// Optional: Extend another theme
extends?: Theme
}
interface EnhanceAppContext {
app: App // Vue app instance
router: Router // VitePress router
siteData: Ref<SiteData> // Site-level metadata
}Basic Layout
Runtime API
Built-in Components
Extend Another Theme
Register Plugins and Components
Async enhanceApp
Theme-Aware Layout
Distributing a Theme
Theme Config Types
Key Points
Last updated
Was this helpful?