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