Skip to content

Getting Started

Get up and running with VitePress Mermaid in minutes.

Choose Your Starting Point

ScenarioRecommended ApproachDescription
Creating a new projectCLI ToolScaffold a pre-configured project with sample diagrams
Existing VitePress projectManual IntegrationInstall and configure the plugin in your existing project

Option 1: Scaffold with CLI

Use the create-vitepress-mermaid CLI tool to create a new pre-configured project:

bash
pnpm create @unify-js/vitepress-mermaid
bash
npm create @unify-js/vitepress-mermaid
bash
yarn create @unify-js/vitepress-mermaid

After creation, follow the instructions to install dependencies and start the dev server:

bash
cd <project-name>
npm install  # or pnpm install, yarn
npm run dev  # or pnpm dev, yarn dev

The generated project includes sample Mermaid diagrams and complete TypeScript configuration.

Option 2: Integrate into Existing Project

Installation

Install the plugin using your preferred package manager:

bash
pnpm add -D @unify-js/vitepress-mermaid
bash
npm install -D @unify-js/vitepress-mermaid
bash
yarn add -D @unify-js/vitepress-mermaid

Dependency Requirements

This custom theme requires the following dependencies to work properly. Please make sure they are installed:

bash
pnpm add -D vitepress mermaid

Configuration

Step 1: Configure VitePress Config

Create or edit your .vitepress/config.ts file:

typescript
import { defineConfig } from 'vitepress';
import vitepressMermaidConfig from '@unify-js/vitepress-mermaid/config';

export default defineConfig({
  extends: vitepressMermaidConfig,
  // Your VitePress config
});

Step 2: Configure the Theme

Create or edit your .vitepress/theme/index.ts file:

typescript
import type { Theme } from 'vitepress';
import { MermaidTheme } from '@unify-js/vitepress-mermaid';
import '@unify-js/vitepress-mermaid/style.css';

export default {
  extends: MermaidTheme,
} satisfies Theme;

Usage

Once configured, you can use Mermaid diagrams in your Markdown files:

markdown
```mermaid
graph TD
  A[Start] --> B{Decision}
  B -->|Yes| C[Action 1]
  B -->|No| D[Action 2]
  C --> E[End]
  D --> E
```

This will render as:

Loading diagram...

Click on the diagram above to open the fullscreen preview!

Interactive Preview

How to Use

  1. Click on any diagram in your documentation
  2. The diagram opens in fullscreen mode
  3. Use your mouse wheel or keyboard to zoom
  4. Drag to pan around the diagram
  5. Press ESC or click the X to close

Example: Complex Diagram

Try interacting with this larger diagram:

Loading diagram...

Click the diagram above to explore it in fullscreen!

Show Source Code

Use mermaid-example to display both the diagram and its source:

markdown
```mermaid-example
graph LR
    A[Input] --> B[Process]
    B --> C[Output]
```
Loading diagram...
graph LR
    A[Input] --> B[Process]
    B --> C[Output]

Released under the MIT License.