コンテンツへスキップ
Fumadocs

手動インストール

既存のNext.jsプロジェクトにFumadocsを追加します。

Fumadocs CLI を使って自動でセットアップすることもできます。

npx @fumadocs/cli init

前提条件

先に進む前に、以下が設定済みであることを確認してください。

  • Next.js 16
  • Tailwind CSS 4

このガイドでは、コンテンツソースとして Fumadocs MDX を使用します。まずはこれを設定してください。

Installation

npm i fumadocs-mdx fumadocs-core @types/mdx

Add the plugin to Next.js config:

next.config.mjs
import { createMDX } from 'fumadocs-mdx/next';

/** @type {import('next').NextConfig} */
const config = {
  reactStrictMode: true,
};

const withMDX = createMDX();

export default withMDX(config);

ESM Only

Fumadocs MDX is ESM-only, it's recommended to use next.config.mjs for accurate ESM resolution.

For TypeScript config file, it requires Native Node.js TypeScript Resolver, you can see Next.js docs for details.

Integrate with Fumadocs

Create a lib/source.ts file:

lib/source.ts
import { defineDocs } from 'fumadocs-mdx/macro';
import { loader } from 'fumadocs-core/source';

const docs = defineDocs({
  dir: 'content/docs',
});

export const source = loader({
  baseUrl: '/docs',
  source: docs.toFumadocsSource(),
});

Done

You can now write content in content/docs folder.

補足

Fumadocs は、Content Collections やヘッドレス CMS など、ほかのコンテンツソースにも対応しています。

はじめに

パッケージをインストールします。

npm i fumadocs-core fumadocs-ui@npm:@fumadocs/base-ui

テンプレートと同様に、このコマンドでは fumadocs-ui を、Fumadocs UI の Base UI 版である @fumadocs/base-ui のエイリアスとしてインストールします。Radix UI を使う場合は、エイリアスなしで fumadocs-ui をインストールしてください。

スタイル

Tailwind CSS ファイルに以下を追加します。

@import 'tailwindcss';
@import 'fumadocs-ui/css/neutral.css';
@import 'fumadocs-ui/css/preset.css';

Fumadocs UI にはデフォルトのフォントが設定されていません。next/font からお好みのフォントを選んでください。

Root Provider

アプリ全体を Root Provider でラップし、body に必要なスタイルを追加してください。

app/layout.tsx
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
        // 必須のスタイル
        className="flex flex-col min-h-screen"
      >
        <RootProvider>{children}</RootProvider>
      </body>
    </html>
  );
}

ルート

レイアウトで共有するオプションを1つのファイルにまとめます。

lib/layout.shared.tsx
import type { BaseLayoutProps } from 'fumadocs-ui/layouts/shared';

export function baseOptions(): BaseLayoutProps {
  return {
    nav: {
      title: 'My App',
    },
  };
}

次のファイルを作成します。

import defaultMdxComponents from 'fumadocs-ui/mdx';
import type { MDXComponents } from 'mdx/types';

export function getMDXComponents(components?: MDXComponents) {
  return {
    ...defaultMdxComponents,
    ...components,
  } satisfies MDXComponents;
}

export const useMDXComponents = getMDXComponents;

declare global {
  type MDXProvidedComponents = ReturnType<typeof getMDXComponents>;
}

検索ルートでは ZBSearch を使用しています。設定方法についてはドキュメント検索を参照してください。

完了

開発サーバーを起動し、content/docs にドキュメントを作成してください。

content/docs/index.mdx
---
title: Hello World
---

## Introduction

I love Fumadocs.

How is this guide?

最終更新日