Slidev - 面向開發者的簡報幻燈片
基於 Vite、Vue 和 Markdown 構建的基於 Web 的幻燈片製作工具。
使用場景
- 帶有實時程式碼示例的技術演示或幻燈片
- 帶有動畫的語法高亮程式碼片段
- 互動式演示(Monaco 編輯器、可執行程式碼)
- 數學公式(LaTeX)或圖表(Mermaid、PlantUML)
- 帶有演講者備註的演示錄製
- 匯出為 PDF、PPTX 或作為單頁應用(SPA)託管
- 開發者演講或工作坊的程式碼逐步講解
快速開始
pnpm create slidev # 建立專案
pnpm run dev # 啟動開發伺服器(開啟 http://localhost:3030)
pnpm run build # 構建靜態 SPA
pnpm run export # 匯出為 PDF(需要 playwright-chromium)
驗證:在執行 pnpm run dev 後,確認幻燈片在 http://localhost:3030 載入正常。在執行 pnpm run export 後,檢查專案根目錄下是否存在輸出的 PDF 檔案。
基本語法
---
theme: default
title: My Presentation
---
# First Slide
Content here
---
# Second Slide
More content
--- 用於分隔幻燈片- 第一個 frontmatter = headmatter(幻燈片集配置)
- HTML 註釋 = 演講者備註
核心參考
| 主題 | 描述 | 參考 |
|---|
| Markdown 語法 | 幻燈片分隔符、frontmatter、備註、程式碼塊 | core-syntax |
| 動畫 | v-click、v-clicks、motion、transitions | core-animations |
| Headmatter | 整個幻燈片集的配置選項 | core-headmatter |
| Frontmatter | 每張幻燈片的配置選項 | core-frontmatter |
| CLI 命令 | 開發、構建、匯出、主題命令 | core-cli |
| 元件 | 內建 Vue 元件 | core-components |
| 佈局 | 內建幻燈片佈局 | core-layouts |
| 匯出 | PDF、PPTX、PNG 匯出選項 | core-exporting |
| 託管 | 構建並部署到各種平臺 | core-hosting |
| 全域性上下文 | $nav、$slidev、composables API | core-global-context |
功能參考
程式碼與編輯器
| 功能 | 用法 | 參考 |
|---|
| 行高亮 | ````ts {2,3}` | code-line-highlighting |
| 基於點選的高亮 | ````ts {1|2-3|all}` | code-line-highlighting |
| 行號 | `lineNumbers: true` 或 `{lines:true}` | code-line-numbers |
| 可滾動程式碼 | `{maxHeight:'100px'}` | code-max-height |
| 程式碼標籤頁 | `::code-group`(需要 `comark: true`) | code-groups |
| Monaco 編輯器 | ````ts {monaco}` | editor-monaco |
| 執行程式碼 | ````ts {monaco-run}` | editor-monaco-run |
| 編輯檔案 | `` | editor-monaco-write |
| 程式碼動畫 | `````md magic-move` | code-magic-move |
| TypeScript 型別 | ````ts twoslash` | code-twoslash |
| 匯入程式碼 | `` | code-import-snippet |
圖表與數學
| 功能 | 用法 | 參考 |
|---|
| Mermaid 圖表 | ````mermaid` | diagram-mermaid |
| PlantUML 圖表 | ````plantuml` | diagram-plantuml |
| LaTeX 數學 | `$inline$` 或 `$$block$$` | diagram-latex |
佈局與樣式
| 功能 | 用法 | 參考 |
|---|
| 畫布大小 | `canvasWidth`、`aspectRatio` | layout-canvas-size |
| 縮放幻燈片 | `zoom: 0.8` | layout-zoom |
| 縮放元素 | `` | layout-transform |
| 佈局插槽 | `::right::`、`::default::` | layout-slots |
| 作用域 CSS | `` 在幻燈片內 | style-scoped |
| 全域性圖層 | `global-top.vue`、`global-bottom.vue` | layout-global-layers |
| 可拖拽元素 | `v-drag`、`` | layout-draggable |
| 圖示 | `` | style-icons |
動畫與互動
| 功能 | 用法 | 參考 |
|---|
| 點選動畫 | `v-click`、`` | core-animations |
| 粗糙標記 | `v-mark.underline`、`v-mark.circle` | animation-rough-marker |
| 繪圖模式 | 按 `C` 鍵或配置 `drawings:` | animation-drawing |
| 方向樣式 | `forward:delay-300` | style-direction |
| 備註高亮 | 備註中的 `[click]` | animation-click-marker |
語法擴充套件
| 功能 | 用法 | 參考 |
|---|
| Comark 語法 | `comark: true` + `{style="color:red"}` | syntax-comark |
| 塊狀 frontmatter | ````yaml` 代替 `---` | syntax-block-frontmatter |
| 匯入幻燈片 | `src: ./other.md` | syntax-importing-slides |
| 合併 frontmatter | 主入口優先 | syntax-frontmatter-merging |
演講者與錄製
| 功能 | 用法 | 參考 |
|---|
| 錄製 | 按 `G` 鍵開啟攝像頭 | presenter-recording |
| 計時器 | `duration: 30min`、`timer: countdown` | presenter-timer |
| 遠端控制 | `slidev --remote` | presenter-remote |
| 注音文字 | `notesAutoRuby:` | presenter-notes-ruby |
匯出與構建
| 功能 | 用法 | 參考 |
|---|
| 匯出選項 | `slidev export` | core-exporting |
| 構建與部署 | `slidev build` | core-hosting |
| 構建包含 PDF | `download: true` | build-pdf |
| 快取圖片 | 遠端 URL 自動處理 | build-remote-assets |
| OG 圖片 | `seoMeta.ogImage` 或 `og-image.png` | build-og-image |
| SEO 標籤 | `seoMeta:` | build-seo-meta |
匯出前提條件:匯出 PDF/PPTX/PNG 需要 pnpm add -D playwright-chromium。如果匯出時出現瀏覽器錯誤,請先安裝此依賴項。
編輯器與工具
| 功能 | 用法 | 參考 |
|---|
| 側邊編輯器 | 點選編輯圖示 | editor-side |
| VS Code 擴充套件 | 安裝 `antfu.slidev` | editor-vscode |
| Prettier | `prettier-plugin-slidev` | editor-prettier |
| 彈出主題 | `slidev theme eject` | tool-eject-theme |
生命週期與 API
| 功能 | 用法 | 參考 |
|---|
| 幻燈片鉤子 | `onSlideEnter()`、`onSlideLeave()` | api-slide-hooks |
| 導航 API | `$nav`、`useNav()` | core-global-context |
常用佈局
| 佈局 | 用途 |
|---|
| `cover` | 標題/封面幻燈片 |
| `center` | 居中內容 |
| `default` | 標準幻燈片 |
| `two-cols` | 兩列(使用 `::right::`) |
| `two-cols-header` | 頁首 + 兩列 |
| `image` / `image-left` / `image-right` | 圖片佈局 |
| `iframe` / `iframe-left` / `iframe-right` | 嵌入 URL |
| `quote` | 引用 |
| `section` | 章節分隔符 |
| `fact` / `statement` | 資料/陳述展示 |
| `intro` / `end` | 介紹/結束幻燈片 |
資源
在 GitHub 上查看
---
name: slidev
description: Create and present web-based slide decks using Slidev with Markdown, Vue components, code highlighting, animations, and interactive features. Ideal for technical presentations, conference talks, code walkthroughs, teaching materials, or developer decks.
---
# Slidev - Presentation Slides for Developers
Web-based slides maker built on Vite, Vue, and Markdown.
## When to Use
- Technical presentations or slidedecks with live code examples
- Syntax-highlighted code snippets with animations
- Interactive demos (Monaco editor, runnable code)
- Mathematical equations (LaTeX) or diagrams (Mermaid, PlantUML)
- Record presentations with presenter notes
- Export to PDF, PPTX, or host as SPA
- Code walkthroughs for developer talks or workshops
## Quick Start
```bash
pnpm create slidev # Create project
pnpm run dev # Start dev server (opens http://localhost:3030)
pnpm run build # Build static SPA
pnpm run export # Export to PDF (requires playwright-chromium)
```
**Verify**: After `pnpm run dev`, confirm slides load at `http://localhost:3030`. After `pnpm run export`, check the output PDF exists in the project root.
## Basic Syntax
```md
---
theme: default
title: My Presentation
---
# First Slide
Content here
---
# Second Slide
More content
<!--
Presenter notes go here
-->
```
- `---` separates slides
- First frontmatter = headmatter (deck config)
- HTML comments = presenter notes
## Core References
| Topic | Description | Reference |
|-------|-------------|-----------|
| Markdown Syntax | Slide separators, frontmatter, notes, code blocks | [core-syntax](references/core-syntax.md) |
| Animations | v-click, v-clicks, motion, transitions | [core-animations](references/core-animations.md) |
| Headmatter | Deck-wide configuration options | [core-headmatter](references/core-headmatter.md) |
| Frontmatter | Per-slide configuration options | [core-frontmatter](references/core-frontmatter.md) |
| CLI Commands | Dev, build, export, theme commands | [core-cli](references/core-cli.md) |
| Components | Built-in Vue components | [core-components](references/core-components.md) |
| Layouts | Built-in slide layouts | [core-layouts](references/core-layouts.md) |
| Exporting | PDF, PPTX, PNG export options | [core-exporting](references/core-exporting.md) |
| Hosting | Build and deploy to various platforms | [core-hosting](references/core-hosting.md) |
| Global Context | $nav, $slidev, composables API | [core-global-context](references/core-global-context.md) |
## Feature Reference
### Code & Editor
| Feature | Usage | Reference |
|---------|-------|-----------|
| Line highlighting | `` ```ts {2,3} `` | [code-line-highlighting](references/code-line-highlighting.md) |
| Click-based highlighting | `` ```ts {1\|2-3\|all} `` | [code-line-highlighting](references/code-line-highlighting.md) |
| Line numbers | `lineNumbers: true` or `{lines:true}` | [code-line-numbers](references/code-line-numbers.md) |
| Scrollable code | `{maxHeight:'100px'}` | [code-max-height](references/code-max-height.md) |
| Code tabs | `::code-group` (requires `comark: true`) | [code-groups](references/code-groups.md) |
| Monaco editor | `` ```ts {monaco} `` | [editor-monaco](references/editor-monaco.md) |
| Run code | `` ```ts {monaco-run} `` | [editor-monaco-run](references/editor-monaco-run.md) |
| Edit files | `<<< ./file.ts {monaco-write}` | [editor-monaco-write](references/editor-monaco-write.md) |
| Code animations | `` ````md magic-move `` | [code-magic-move](references/code-magic-move.md) |
| TypeScript types | `` ```ts twoslash `` | [code-twoslash](references/code-twoslash.md) |
| Import code | `<<< @/snippets/file.js` | [code-import-snippet](references/code-import-snippet.md) |
### Diagrams & Math
| Feature | Usage | Reference |
|---------|-------|-----------|
| Mermaid diagrams | `` ```mermaid `` | [diagram-mermaid](references/diagram-mermaid.md) |
| PlantUML diagrams | `` ```plantuml `` | [diagram-plantuml](references/diagram-plantuml.md) |
| LaTeX math | `$inline$` or `$$block$$` | [diagram-latex](references/diagram-latex.md) |
### Layout & Styling
| Feature | Usage | Reference |
|---------|-------|-----------|
| Canvas size | `canvasWidth`, `aspectRatio` | [layout-canvas-size](references/layout-canvas-size.md) |
| Zoom slide | `zoom: 0.8` | [layout-zoom](references/layout-zoom.md) |
| Scale elements | `<Transform :scale="0.5">` | [layout-transform](references/layout-transform.md) |
| Layout slots | `::right::`, `::default::` | [layout-slots](references/layout-slots.md) |
| Scoped CSS | `<style>` in slide | [style-scoped](references/style-scoped.md) |
| Global layers | `global-top.vue`, `global-bottom.vue` | [layout-global-layers](references/layout-global-layers.md) |
| Draggable elements | `v-drag`, `<v-drag>` | [layout-draggable](references/layout-draggable.md) |
| Icons | `<mdi-icon-name />` | [style-icons](references/style-icons.md) |
### Animation & Interaction
| Feature | Usage | Reference |
|---------|-------|-----------|
| Click animations | `v-click`, `<v-clicks>` | [core-animations](references/core-animations.md) |
| Rough markers | `v-mark.underline`, `v-mark.circle` | [animation-rough-marker](references/animation-rough-marker.md) |
| Drawing mode | Press `C` or config `drawings:` | [animation-drawing](references/animation-drawing.md) |
| Direction styles | `forward:delay-300` | [style-direction](references/style-direction.md) |
| Note highlighting | `[click]` in notes | [animation-click-marker](references/animation-click-marker.md) |
### Syntax Extensions
| Feature | Usage | Reference |
|---------|-------|-----------|
| Comark syntax | `comark: true` + `{style="color:red"}` | [syntax-comark](references/syntax-comark.md) |
| Block frontmatter | `` ```yaml `` instead of `---` | [syntax-block-frontmatter](references/syntax-block-frontmatter.md) |
| Import slides | `src: ./other.md` | [syntax-importing-slides](references/syntax-importing-slides.md) |
| Merge frontmatter | Main entry wins | [syntax-frontmatter-merging](references/syntax-frontmatter-merging.md) |
### Presenter & Recording
| Feature | Usage | Reference |
|---------|-------|-----------|
| Recording | Press `G` for camera | [presenter-recording](references/presenter-recording.md) |
| Timer | `duration: 30min`, `timer: countdown` | [presenter-timer](references/presenter-timer.md) |
| Remote control | `slidev --remote` | [presenter-remote](references/presenter-remote.md) |
| Ruby text | `notesAutoRuby:` | [presenter-notes-ruby](references/presenter-notes-ruby.md) |
### Export & Build
| Feature | Usage | Reference |
|---------|-------|-----------|
| Export options | `slidev export` | [core-exporting](references/core-exporting.md) |
| Build & deploy | `slidev build` | [core-hosting](references/core-hosting.md) |
| Build with PDF | `download: true` | [build-pdf](references/build-pdf.md) |
| Cache images | Automatic for remote URLs | [build-remote-assets](references/build-remote-assets.md) |
| OG image | `seoMeta.ogImage` or `og-image.png` | [build-og-image](references/build-og-image.md) |
| SEO tags | `seoMeta:` | [build-seo-meta](references/build-seo-meta.md) |
**Export prerequisite**: `pnpm add -D playwright-chromium` is required for PDF/PPTX/PNG export. If export fails with a browser error, install this dependency first.
### Editor & Tools
| Feature | Usage | Reference |
|---------|-------|-----------|
| Side editor | Click edit icon | [editor-side](references/editor-side.md) |
| VS Code extension | Install `antfu.slidev` | [editor-vscode](references/editor-vscode.md) |
| Prettier | `prettier-plugin-slidev` | [editor-prettier](references/editor-prettier.md) |
| Eject theme | `slidev theme eject` | [tool-eject-theme](references/tool-eject-theme.md) |
### Lifecycle & API
| Feature | Usage | Reference |
|---------|-------|-----------|
| Slide hooks | `onSlideEnter()`, `onSlideLeave()` | [api-slide-hooks](references/api-slide-hooks.md) |
| Navigation API | `$nav`, `useNav()` | [core-global-context](references/core-global-context.md) |
## Common Layouts
| Layout | Purpose |
|--------|---------|
| `cover` | Title/cover slide |
| `center` | Centered content |
| `default` | Standard slide |
| `two-cols` | Two columns (use `::right::`) |
| `two-cols-header` | Header + two columns |
| `image` / `image-left` / `image-right` | Image layouts |
| `iframe` / `iframe-left` / `iframe-right` | Embed URLs |
| `quote` | Quotation |
| `section` | Section divider |
| `fact` / `statement` | Data/statement display |
| `intro` / `end` | Intro/end slides |
## Resources
- Documentation: https://sli.dev
- Theme Gallery: https://sli.dev/resources/theme-gallery
- Showcases: https://sli.dev/resources/showcases