Documentation Application for UI8Kit Framework
A docs-first application where all routes are automatically derived from MDX files in the docs/ folder. Features live development with Vite HMR and static generation for production deployment.
# Install dependencies
bun install
# Start development server (Vite + HMR)
bun run dev
# Generate static documentation
bun run generate
# Preview generated static site
bun run serveUnlike @ui8kit/vite-web, this application uses file-based routing from MDX:
docs/
├── index.mdx → /
├── components/
│ ├── index.mdx → /components
│ ├── button.mdx → /components/button
│ └── card.mdx → /components/card
└── tutorials/
└── getting-started.mdx → /tutorials/getting-started
No route configuration needed — the generator scans docs/ and creates routes automatically.
bun run dev- Full React hydration
- MDX hot module replacement
- Live component preview
- Fast refresh on file changes
bun run generate- Scans
docs/folder for MDX files - Generates static HTML pages
- Creates navigation JSON (
docs-nav.json) - Outputs pure CSS for production
| Feature | vite-web | vite-docs |
|---|---|---|
| Route source | config.html.routes |
docs/ folder (MDX) |
| HTML routes | Defined manually | Auto-discovered |
| MDX support | No | Yes |
| Navigation | Manual | Auto-generated JSON |
mdx: {
enabled: true, // Enable MDX processing
docsDir: './docs', // Source MDX folder
outputDir: './dist/html', // Output HTML folder
navOutput: './dist/docs-nav.json', // Navigation structure
basePath: '', // URL prefix (empty = root)
// Components available in MDX without imports
components: {
Button: '@/components/ui/Button',
Card: '@/components/Card',
Badge: '@/components/ui/Badge',
Stack: '@/components/ui/Stack',
Box: '@/components/ui/Box',
Grid: '@/components/Grid',
Text: '@/components/ui/Text',
Title: '@/components/ui/Title',
},
propsSource: './src/components', // Source for props extraction
toc: {
minLevel: 2, // Min heading level for TOC
maxLevel: 3, // Max heading level for TOC
},
}html: {
viewsDir: './views',
routes: {}, // Empty! Routes come from MDX
outputDir: './dist/html',
mode: 'tailwind',
}# Default: Tailwind mode (keeps class + data-class)
bun run generate
# Semantic mode: removes Tailwind classes, uses data-class → class
bun run generate --semantic
# Inline mode: embeds CSS in HTML
bun run generate --inline
# Pure mode: removes data-class attributes
bun run generate --pure
# Combine flags
bun run generate --semantic --pure| Mode | class |
data-class |
CSS |
|---|---|---|---|
tailwind |
✅ Kept | ✅ Kept | External |
semantic |
From data-class | ❌ Removed | External |
inline |
From data-class | ❌ Removed | <style> in HTML |
In development, DocsPage.tsx handles all routing dynamically.
// 1. Vite glob imports all MDX files
const mdxModules = import.meta.glob('../../docs/**/*.mdx')
// 2. URL pathname → MDX module path
getMdxPath('/components/button') // → '../../docs/components/button.mdx'
// 3. Dynamic import with React Suspense
const loader = mdxModules[mdxPath]
const { default: Content, frontmatter, toc } = await loader()
// 4. Render with PageContentProvider
<PageContentProvider content={Content} frontmatter={frontmatter} toc={toc}>
<DocsLayout />
</PageContentProvider>// React context and hooks
import {
PageContentProvider, // Wraps content with context
usePageContent, // Access { Content, frontmatter, toc }
useToc, // Just the TOC array
useFrontmatter, // Just the frontmatter object
} from '@ui8kit/mdx-react'
// Type definitions
import type {
TocEntry, // { depth, text, slug }
Frontmatter, // { title?, description?, order?, ... }
} from '@ui8kit/mdx-react'// Full page content
const { Content, frontmatter, toc, excerpt } = usePageContent()
// Table of contents only
const toc = useToc()
// [{ depth: 2, text: 'Usage', slug: 'usage' }, ...]
// Frontmatter only
const { title, description, order } = useFrontmatter()---
title: Button Component
description: Interactive button with multiple variants
order: 1
---
# Button
A versatile button component for user interactions.
## Usage
<Button variant="primary">Click me</Button>
## Variants
### Primary
<Button variant="primary">Primary</Button>
### Secondary
<Button variant="secondary">Secondary</Button>| Field | Type | Description |
|---|---|---|
title |
string | Page title (used in nav and <title>) |
description |
string | Meta description for SEO |
order |
number | Sort order in navigation (lower = first) |
Components defined in mdx.components are available without imports:
{/* These work automatically */}
<Button variant="primary">Click</Button>
<Card>Content</Card>
<Stack gap="md">
<Box>Item 1</Box>
<Box>Item 2</Box>
</Stack>After bun run generate:
dist/
├── assets/
│ └── js/
│ └── main.js # Client script
├── css/
│ ├── index.css # Copied styles
│ ├── shadcn.css # Copied styles
│ ├── tailwind.apply.css # Generated @apply CSS
│ ├── ui8kit.local.css # Generated pure CSS
│ └── variants.apply.css # Component variants
├── docs-nav.json # Navigation structure
└── html/
├── index.html # /
├── components/
│ ├── index.html # /components
│ ├── button/
│ │ └── index.html # /components/button
│ └── card/
│ └── index.html # /components/card
└── tutorials/
└── getting-started/
└── index.html # /tutorials/getting-started
The generated docs-nav.json provides navigation structure:
[
{ "title": "Home", "path": "/", "order": 0 },
{ "title": "Components", "path": "/components", "order": 1 },
{ "title": "Button Component", "path": "/components/button", "order": 2 },
{ "title": "Card Component", "path": "/components/card", "order": 3 },
{ "title": "Getting Started", "path": "/tutorials/getting-started", "order": 10 }
]- Initialize Layouts — Copy templates if missing
- Generate CSS — Extract and generate stylesheets
- Copy Assets — Static files to
dist/ - Generate Client Script — Dark mode, utilities
- Generate Elements — Typed variant components
- Generate MDX Docs — Scan
docs/, create HTML + nav JSON
react,react-dom— React 19react-router-dom— Client-side routing (dev mode)lucide-react— Icons
@mdx-js/react,@mdx-js/rollup— MDX compilerrehype-slug— Auto-generate heading IDsremark-frontmatter— Parse YAML frontmatterremark-gfm— GitHub Flavored Markdownremark-mdx-frontmatter— Expose frontmatter in MDX
@ui8kit/generator— Static generation@ui8kit/mdx-react— MDX utilities and components
- Create MDX file in
docs/:
# New component doc
touch docs/components/accordion.mdx
# New tutorial
touch docs/tutorials/styling.mdx- Add frontmatter:
---
title: Accordion
description: Expandable content sections
order: 5
---
# Accordion
...content...- Generate:
bun run generateThe new page automatically appears in navigation.
- UI8Kit Framework
- Generator Package
- MDX-React Package
- @ui8kit/vite-web — Static site without MDX