Next.js
Setup Fumadocs on Next.js.
Prerequisite
Before continuing, make sure you have configured:
- Next.js 15.
 - Tailwind CSS 4.
 
We will use Fumadocs MDX as a content source, you can configure it first:
Installation
npm i fumadocs-mdx @types/mdxCreate the configuration file:
import { defineDocs, defineConfig } from 'fumadocs-mdx/config';
export const docs = defineDocs({
  dir: 'content/docs',
});
export default defineConfig();Add the plugin to Next.js config:
import { createMDX } from 'fumadocs-mdx/next';
/** @type {import('next').NextConfig} */
const config = {
  reactStrictMode: true,
};
const withMDX = createMDX({
  // customise the config file path
  // configPath: "source.config.ts"
});
export default withMDX(config);ESM Only
The Next.js config must be a .mjs file since Fumadocs is ESM-only.
Integrate with Fumadocs
You can create a lib/source.ts file and obtain Fumadocs source from the docs collection output.
import { docs } from '@/.source';
import { loader } from 'fumadocs-core/source';
export const source = loader({
  baseUrl: '/docs',
  source: docs.toFumadocsSource(),
});.source will be generated when you run next dev or next build.
Make sure you are importing the .source rather than source.config.ts.
Integrate with CI (Optional)
You can run fumadocs-mdx to generate the .source folder.
Optionally, you can run it in post install to ensure types are generated when initializing the project.
{
  "scripts": {
    "postinstall": "fumadocs-mdx"
  }
}Done
You can now write content in content/docs folder.
Good to Know
Fumadocs also supports other content sources, including Content Collections and headless CMS.
Getting Started
npm i fumadocs-ui fumadocs-coreCreate a file for MDX components:
import defaultMdxComponents from 'fumadocs-ui/mdx';
import type { MDXComponents } from 'mdx/types';
export function getMDXComponents(components?: MDXComponents): MDXComponents {
  return {
    ...defaultMdxComponents,
    ...components,
  };
}Root Layout
Wrap the entire application inside Root Provider, and add required styles to body.
import { RootProvider } from 'fumadocs-ui/provider/next';
import type { ReactNode } from 'react';
export default function Layout({ children }: { children: ReactNode }) {
  return (
    <html lang="en" suppressHydrationWarning>
      <body
        // you can use Tailwind CSS too
        style={{
          display: 'flex',
          flexDirection: 'column',
          minHeight: '100vh',
        }}
      >
        <RootProvider>{children}</RootProvider>
      </body>
    </html>
  );
}Styles
Add the following Tailwind CSS styles to global.css.
@import 'tailwindcss';
@import 'fumadocs-ui/css/neutral.css';
@import 'fumadocs-ui/css/preset.css';It doesn't come with a default font, you may choose one from next/font.
Routes
Create a lib/layout.shared.tsx file to put the shared options for our layouts.
import type { BaseLayoutProps } from 'fumadocs-ui/layouts/shared';
export function baseOptions(): BaseLayoutProps {
  return {
    nav: {
      title: 'My App',
    },
  };
}Create the following routes:
import { source } from '@/lib/source';
import { DocsLayout } from 'fumadocs-ui/layouts/docs';
import { baseOptions } from '@/lib/layout.shared';
export default function Layout({ children }: LayoutProps<'/docs'>) {
  return (
    <DocsLayout tree={source.pageTree} {...baseOptions()}>
      {children}
    </DocsLayout>
  );
}The search is powered by Orama, learn more about Document Search.
Finish
You can start the dev server and create MDX files.
---
title: Hello World
---
## Introduction
I love Anime.Deploying
It should work out-of-the-box with Vercel & Netlify.
Cloudflare
Use https://opennext.js.org/cloudflare, Fumadocs doesn't work on Edge runtime.
Docker Deployment
If you want to deploy your Fumadocs app using Docker with Fumadocs MDX configured, make sure to add the source.config.ts file to the WORKDIR in the Dockerfile.
The following snippet is taken from the official Next.js Dockerfile Example:
# syntax=docker.io/docker/dockerfile:1
FROM node:18-alpine AS base
# Install dependencies only when needed
FROM base AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app
# Install dependencies based on the preferred package manager
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* .npmrc* source.config.ts ./
RUN \
  if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
  elif [ -f package-lock.json ]; then npm ci; \
  elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
  else echo "Lockfile not found." && exit 1; \
  fi
# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry during the build.
# ENV NEXT_TELEMETRY_DISABLED=1
RUN \
  if [ -f yarn.lock ]; then yarn run build; \
  elif [ -f package-lock.json ]; then npm run build; \
  elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
  else echo "Lockfile not found." && exit 1; \
  fi
# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app
ENV NODE_ENV=production
# Uncomment the following line in case you want to disable telemetry during runtime.
# ENV NEXT_TELEMETRY_DISABLED=1
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
COPY --from=builder /app/public ./public
# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
USER nextjs
EXPOSE 3000
ENV PORT=3000
# server.js is created by next build from the standalone output
# https://nextjs.org/docs/pages/api-reference/config/next-config-js/output
ENV HOSTNAME="0.0.0.0"
CMD ["node", "server.js"]This ensures Fumadocs MDX can access your configuration file during builds.
How is this guide?
Last updated on
