Vite
Use Fumadocs MDX with Vite
Setup
Installation
npm i fumadocs-mdx fumadocs-core @types/mdxCreate the configuration file:
import { defineDocs } from 'fumadocs-mdx/config';
export const docs = defineDocs({
dir: 'content/docs',
});Add the Vite plugin:
import { defineConfig } from 'vite';
import mdx from 'fumadocs-mdx/vite';
import * as MdxConfig from './source.config';
export default defineConfig({
plugins: [
mdx(MdxConfig),
// ...
],
});Setup an import alias (recommended):
{
"compilerOptions": {
"paths": {
"fumadocs-mdx:collections/*": [".source/*"]
}
}
}You might need to configure vite-tsconfig-paths plugin for path alias.
Integrate with Fumadocs
To integrate with Fumadocs, make a lib/source.ts file:
import { docs } from 'fumadocs-mdx:collections/server';
import { loader } from 'fumadocs-core/source';
export const source = loader({
baseUrl: '/docs',
source: docs.toFumadocsSource(),
});The .source folder will be generated when you run development server or production build.
Done
You can now write content in content/docs folder.
What is Next?
How is this guide?
Last updated on
