@slidev/docs 51.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +39 -0
- package/builtin/cli.md +96 -0
- package/builtin/components.md +359 -0
- package/builtin/layouts.md +217 -0
- package/custom/config-code-runners.md +78 -0
- package/custom/config-context-menu.md +40 -0
- package/custom/config-fonts.md +105 -0
- package/custom/config-highlighter.md +74 -0
- package/custom/config-katex.md +18 -0
- package/custom/config-mermaid.md +47 -0
- package/custom/config-monaco.md +99 -0
- package/custom/config-parser.md +232 -0
- package/custom/config-routes.md +28 -0
- package/custom/config-shortcuts.md +36 -0
- package/custom/config-transformers.md +43 -0
- package/custom/config-unocss.md +46 -0
- package/custom/config-vite.md +83 -0
- package/custom/config-vue.md +25 -0
- package/custom/directory-structure.md +134 -0
- package/custom/index.md +192 -0
- package/features/block-frontmatter.md +39 -0
- package/features/build-with-pdf.md +42 -0
- package/features/bundle-remote-assets.md +29 -0
- package/features/canvas-size.md +32 -0
- package/features/click-marker.md +31 -0
- package/features/code-block-line-numbers.md +32 -0
- package/features/code-block-max-height.md +32 -0
- package/features/direction-variant.md +31 -0
- package/features/draggable.md +82 -0
- package/features/drawing.md +74 -0
- package/features/eject-theme.md +27 -0
- package/features/frontmatter-merging.md +49 -0
- package/features/global-layers.md +99 -0
- package/features/icons.md +58 -0
- package/features/import-snippet.md +48 -0
- package/features/importing-slides.md +69 -0
- package/features/index.md +93 -0
- package/features/latex.md +80 -0
- package/features/line-highlighting.md +57 -0
- package/features/mdc.md +31 -0
- package/features/mermaid.md +37 -0
- package/features/monaco-editor.md +36 -0
- package/features/monaco-run.md +44 -0
- package/features/monaco-write.md +22 -0
- package/features/plantuml.md +26 -0
- package/features/prettier-plugin.md +55 -0
- package/features/recording.md +28 -0
- package/features/remote-access.md +69 -0
- package/features/rough-marker.md +46 -0
- package/features/shiki-magic-move.md +53 -0
- package/features/side-editor.md +17 -0
- package/features/slide-hook.md +33 -0
- package/features/slide-scope-style.md +44 -0
- package/features/slot-sugar.md +83 -0
- package/features/transform-component.md +29 -0
- package/features/twoslash.md +37 -0
- package/features/vscode-extension.md +80 -0
- package/features/zoom-slide.md +33 -0
- package/guide/animations.md +456 -0
- package/guide/component.md +36 -0
- package/guide/exporting.md +240 -0
- package/guide/faq.md +134 -0
- package/guide/global-context.md +169 -0
- package/guide/hosting.md +220 -0
- package/guide/index.md +161 -0
- package/guide/layout.md +32 -0
- package/guide/syntax.md +179 -0
- package/guide/theme-addon.md +62 -0
- package/guide/ui.md +86 -0
- package/guide/why.md +112 -0
- package/guide/write-addon.md +48 -0
- package/guide/write-layout.md +45 -0
- package/guide/write-theme.md +109 -0
- package/index.md +6 -0
- package/package.json +47 -0
- package/resources/addon-gallery.md +32 -0
- package/resources/covers.md +16 -0
- package/resources/learning.md +22 -0
- package/resources/showcases.md +10 -0
- package/resources/theme-gallery.md +32 -0
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
# Configure Pre-Parser
|
|
2
|
+
|
|
3
|
+
::: info
|
|
4
|
+
Custom pre-parsers are not supposed to be used too often. Usually you can use [Transformers](./config-transformers) for custom syntaxes.
|
|
5
|
+
:::
|
|
6
|
+
|
|
7
|
+
Slidev parses your presentation file (e.g. `slides.md`) in three steps:
|
|
8
|
+
|
|
9
|
+
1. A "preparsing" step is carried out: the file is split into slides using the `---` separator, and considering the possible frontmatter blocks.
|
|
10
|
+
2. Each slide is parsed with an external library.
|
|
11
|
+
3. Slidev resolves the special frontmatter property `src: ....`, which allows to include other md files.
|
|
12
|
+
|
|
13
|
+
## Markdown Parser
|
|
14
|
+
|
|
15
|
+
Configuring the markdown parser used in step 2 can be done by [configuring Vite internal plugins](/custom/config-vite#configure-internal-plugins).
|
|
16
|
+
|
|
17
|
+
## Preparser Extensions
|
|
18
|
+
|
|
19
|
+
> Available since v0.37.0.
|
|
20
|
+
|
|
21
|
+
::: warning
|
|
22
|
+
Important: when modifying the preparser configuration, you need to stop and start Slidev again (restart might not be sufficient).
|
|
23
|
+
:::
|
|
24
|
+
|
|
25
|
+
The preparser (step 1 above) is highly extensible and allows you to implement custom syntaxes for your md files. Extending the preparser is considered **an advanced feature** and is susceptible to breaking [editor integrations](../features/side-editor) due to implicit changes in the syntax.
|
|
26
|
+
|
|
27
|
+
To customize it, create a `./setup/preparser.ts` file with the following content:
|
|
28
|
+
|
|
29
|
+
```ts twoslash
|
|
30
|
+
import { definePreparserSetup } from '@slidev/types'
|
|
31
|
+
|
|
32
|
+
export default definePreparserSetup(({ filepath, headmatter, mode }) => {
|
|
33
|
+
return [
|
|
34
|
+
{
|
|
35
|
+
transformRawLines(lines) {
|
|
36
|
+
for (const i in lines) {
|
|
37
|
+
if (lines[i] === '@@@')
|
|
38
|
+
lines[i] = 'HELLO'
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
}
|
|
42
|
+
]
|
|
43
|
+
})
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
This example systematically replaces any `@@@` line with a line with `hello`. It illustrates the structure of a preparser configuration file and some of the main concepts the preparser involves:
|
|
47
|
+
|
|
48
|
+
- `definePreparserSetup` must be called with a function as parameter.
|
|
49
|
+
- The function receives the file path (of the root presentation file), the headmatter (from the md file) and, since v0.48.0, a mode (dev, build or export). It could use this information (e.g., enable extensions based on the presentation file or whether we are exporting a PDF).
|
|
50
|
+
- The function must return a list of preparser extensions.
|
|
51
|
+
- An extension can contain:
|
|
52
|
+
- a `transformRawLines(lines)` function that runs just after parsing the headmatter of the md file and receives a list of all lines (from the md file). The function can mutate the list arbitrarily.
|
|
53
|
+
- a `transformSlide(content, frontmatter)` function that is called for each slide, just after splitting the file, and receives the slide content as a string and the frontmatter of the slide as an object. The function can mutate the frontmatter and must return the content string (possibly modified, possibly `undefined` if no modifications have been done).
|
|
54
|
+
- a `transformNote(note, frontmatter)` function that is called for each slide, just after splitting the file, and receives the slide note as a string or undefined and the frontmatter of the slide as an object. The function can mutate the frontmatter and must return the note string (possibly modified, possibly `undefined` if no modifications have been done).
|
|
55
|
+
- a `name`
|
|
56
|
+
|
|
57
|
+
## Example Preparser Extensions
|
|
58
|
+
|
|
59
|
+
### Use case 1: compact syntax top-level presentation
|
|
60
|
+
|
|
61
|
+
Imagine a situation where (part of) your presentation is mainly showing cover images and including other md files. You might want a compact notation where for instance (part of) `slides.md` is as follows:
|
|
62
|
+
|
|
63
|
+
<!-- eslint-skip -->
|
|
64
|
+
|
|
65
|
+
```md
|
|
66
|
+
@cover: /nice.jpg
|
|
67
|
+
# Welcome
|
|
68
|
+
@src: page1.md
|
|
69
|
+
@src: page2.md
|
|
70
|
+
@cover: /break.jpg
|
|
71
|
+
@src: pages3-4.md
|
|
72
|
+
@cover: https://cover.sli.dev
|
|
73
|
+
# Questions?
|
|
74
|
+
see you next time
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
To allow these `@src:` and `@cover:` syntaxes, create a `./setup/preparser.ts` file with the following content:
|
|
78
|
+
|
|
79
|
+
```ts twoslash
|
|
80
|
+
import { definePreparserSetup } from '@slidev/types'
|
|
81
|
+
|
|
82
|
+
export default definePreparserSetup(() => {
|
|
83
|
+
return [
|
|
84
|
+
{
|
|
85
|
+
transformRawLines(lines) {
|
|
86
|
+
let i = 0
|
|
87
|
+
while (i < lines.length) {
|
|
88
|
+
const l = lines[i]
|
|
89
|
+
if (l.match(/^@cover:/i)) {
|
|
90
|
+
lines.splice(
|
|
91
|
+
i,
|
|
92
|
+
1,
|
|
93
|
+
'---',
|
|
94
|
+
'layout: cover',
|
|
95
|
+
`background: ${l.replace(/^@cover: */i, '')}`,
|
|
96
|
+
'---',
|
|
97
|
+
''
|
|
98
|
+
)
|
|
99
|
+
continue
|
|
100
|
+
}
|
|
101
|
+
if (l.match(/^@src:/i)) {
|
|
102
|
+
lines.splice(
|
|
103
|
+
i,
|
|
104
|
+
1,
|
|
105
|
+
'---',
|
|
106
|
+
`src: ${l.replace(/^@src: */i, '')}`,
|
|
107
|
+
'---',
|
|
108
|
+
''
|
|
109
|
+
)
|
|
110
|
+
continue
|
|
111
|
+
}
|
|
112
|
+
i++
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
]
|
|
117
|
+
})
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
And that's it.
|
|
121
|
+
|
|
122
|
+
### Use case 2: using custom frontmatter to wrap slides
|
|
123
|
+
|
|
124
|
+
Imagine a case where you often want to scale some of your slides but still want to use a variety of existing layouts so creating a new layout would not be suited.
|
|
125
|
+
For instance, you might want to write your `slides.md` as follows:
|
|
126
|
+
|
|
127
|
+
<!-- eslint-skip -->
|
|
128
|
+
|
|
129
|
+
```md
|
|
130
|
+
---
|
|
131
|
+
layout: quote
|
|
132
|
+
_scale: 0.75
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
# Welcome
|
|
136
|
+
|
|
137
|
+
> great!
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
_scale: 4
|
|
141
|
+
---
|
|
142
|
+
# Break
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
# Ok
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
layout: center
|
|
150
|
+
_scale: 2.5
|
|
151
|
+
---
|
|
152
|
+
# Questions?
|
|
153
|
+
see you next time
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Here we used an underscore in `_scale` to avoid possible conflicts with existing frontmatter properties (indeed, the case of `scale`, without underscore would cause potential problems).
|
|
157
|
+
|
|
158
|
+
To handle this `_scale: ...` syntax in the frontmatter, create a `./setup/preparser.ts` file with the following content:
|
|
159
|
+
|
|
160
|
+
```ts twoslash
|
|
161
|
+
import { definePreparserSetup } from '@slidev/types'
|
|
162
|
+
|
|
163
|
+
export default definePreparserSetup(() => {
|
|
164
|
+
return [
|
|
165
|
+
{
|
|
166
|
+
async transformSlide(content, frontmatter) {
|
|
167
|
+
if ('_scale' in frontmatter) {
|
|
168
|
+
return [
|
|
169
|
+
`<Transform :scale=${frontmatter._scale}>`,
|
|
170
|
+
'',
|
|
171
|
+
content,
|
|
172
|
+
'',
|
|
173
|
+
'</Transform>'
|
|
174
|
+
].join('\n')
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
]
|
|
179
|
+
})
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
And that's it.
|
|
183
|
+
|
|
184
|
+
### Use case 3: using custom frontmatter to transform note
|
|
185
|
+
|
|
186
|
+
Imagine a case where you want to replace the slides default notes with custom notes.
|
|
187
|
+
For instance, you might want to write your `slides.md` as follows:
|
|
188
|
+
|
|
189
|
+
<!-- eslint-skip -->
|
|
190
|
+
|
|
191
|
+
```md
|
|
192
|
+
---
|
|
193
|
+
layout: quote
|
|
194
|
+
_note: notes/note.md
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
# Welcome
|
|
198
|
+
|
|
199
|
+
> great!
|
|
200
|
+
|
|
201
|
+
<!--
|
|
202
|
+
Default slide notes
|
|
203
|
+
-->
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
Here we used an underscore in `_note` to avoid possible conflicts with existing frontmatter properties.
|
|
207
|
+
|
|
208
|
+
To handle this `_note: ...` syntax in the frontmatter, create a `./setup/preparser.ts` file with the following content:
|
|
209
|
+
|
|
210
|
+
```ts twoslash
|
|
211
|
+
import fs, { promises as fsp } from 'node:fs'
|
|
212
|
+
import { definePreparserSetup } from '@slidev/types'
|
|
213
|
+
|
|
214
|
+
export default definePreparserSetup(() => {
|
|
215
|
+
return [
|
|
216
|
+
{
|
|
217
|
+
async transformNote(note, frontmatter) {
|
|
218
|
+
if ('_note' in frontmatter && fs.existsSync(frontmatter._note)) {
|
|
219
|
+
try {
|
|
220
|
+
const newNote = await fsp.readFile(frontmatter._note, 'utf8')
|
|
221
|
+
return newNote
|
|
222
|
+
}
|
|
223
|
+
catch (err) {
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return note
|
|
228
|
+
},
|
|
229
|
+
},
|
|
230
|
+
]
|
|
231
|
+
})
|
|
232
|
+
```
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Configure Routes
|
|
2
|
+
|
|
3
|
+
<Environment type="client" />
|
|
4
|
+
|
|
5
|
+
Add custom pages to the Slidev app.
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
Create `./setup/routes.ts` with the following content:
|
|
10
|
+
|
|
11
|
+
```ts twoslash
|
|
12
|
+
import { defineRoutesSetup } from '@slidev/types'
|
|
13
|
+
|
|
14
|
+
export default defineRoutesSetup((routes) => {
|
|
15
|
+
return [
|
|
16
|
+
...routes,
|
|
17
|
+
{
|
|
18
|
+
path: '/my-page',
|
|
19
|
+
// ---cut-start---
|
|
20
|
+
// @ts-expect-error missing types
|
|
21
|
+
// ---cut-end---
|
|
22
|
+
component: () => import('../pages/my-page.vue'),
|
|
23
|
+
},
|
|
24
|
+
]
|
|
25
|
+
})
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Learn more about routes in the [Vue Router documentation](https://router.vuejs.org/).
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Configure Shortcuts
|
|
2
|
+
|
|
3
|
+
<Environment type="client" />
|
|
4
|
+
|
|
5
|
+
## Getting started
|
|
6
|
+
|
|
7
|
+
Create `./setup/shortcuts.ts` with the following content:
|
|
8
|
+
|
|
9
|
+
```ts twoslash
|
|
10
|
+
import type { NavOperations, ShortcutOptions } from '@slidev/types'
|
|
11
|
+
import { defineShortcutsSetup } from '@slidev/types'
|
|
12
|
+
|
|
13
|
+
export default defineShortcutsSetup((nav: NavOperations, base: ShortcutOptions[]) => {
|
|
14
|
+
return [
|
|
15
|
+
...base, // keep the existing shortcuts
|
|
16
|
+
{
|
|
17
|
+
key: 'enter',
|
|
18
|
+
fn: () => nav.next(),
|
|
19
|
+
autoRepeat: true,
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
key: 'backspace',
|
|
23
|
+
fn: () => nav.prev(),
|
|
24
|
+
autoRepeat: true,
|
|
25
|
+
},
|
|
26
|
+
]
|
|
27
|
+
})
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
In the setup function, you can customize the keyboard shortcuts by returning a new array of shortcuts. The above example binds the `next` operation to <kbd>enter</kbd> and the `prev` operation to <kbd>backspace</kbd>.
|
|
31
|
+
|
|
32
|
+
Please refer to [Navigation Actions](../guide/ui#navigation-actions) section for the default shortcuts and navigation operations.
|
|
33
|
+
|
|
34
|
+
## Key Binding Format
|
|
35
|
+
|
|
36
|
+
The `key` of each shortcut can be either a string (e.g. `'Shift+Ctrl+A'`) or a computed boolean. Please refer to [`useMagicKeys` from VueUse](https://vueuse.org/core/useMagicKeys/) for
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Configure Transformers
|
|
2
|
+
|
|
3
|
+
<Environment type="node" />
|
|
4
|
+
|
|
5
|
+
This setup function allows you to define custom transformers for the markdown content of **each slide**. This is useful when you want to add custom Markdown syntax and render custom code blocks. To start, create a `./setup/transformers.ts` file with the following content:
|
|
6
|
+
|
|
7
|
+
````ts twoslash
|
|
8
|
+
import type { MarkdownTransformContext } from '@slidev/types'
|
|
9
|
+
import { defineTransformersSetup } from '@slidev/types'
|
|
10
|
+
|
|
11
|
+
function myCodeblock(ctx: MarkdownTransformContext) {
|
|
12
|
+
console.log('index in presentation', ctx.slide.index)
|
|
13
|
+
ctx.s.replace(
|
|
14
|
+
/^```myblock *(\{[^\n]*\})?\n([\s\S]+?)\n```/gm,
|
|
15
|
+
(full, options = '', code = '') => {
|
|
16
|
+
return `...`
|
|
17
|
+
},
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export default defineTransformersSetup(() => {
|
|
22
|
+
return {
|
|
23
|
+
pre: [],
|
|
24
|
+
preCodeblock: [myCodeblock],
|
|
25
|
+
postCodeblock: [],
|
|
26
|
+
post: [],
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
````
|
|
30
|
+
|
|
31
|
+
The return value should be the custom options for the transformers. The `pre`, `preCodeblock`, `postCodeblock`, and `post` are arrays of functions that will be called in order to transform the markdown content. The order of the transformers is:
|
|
32
|
+
|
|
33
|
+
1. `pre` from your project
|
|
34
|
+
2. `pre` from addons and themes
|
|
35
|
+
3. Import snippets syntax and Shiki magic move
|
|
36
|
+
4. `preCodeblock` from your project
|
|
37
|
+
5. `preCodeblock` from addons and themes
|
|
38
|
+
6. Built-in special code blocks like Mermaid, Monaco and PlantUML
|
|
39
|
+
7. `postCodeblock` from addons and themes
|
|
40
|
+
8. `postCodeblock` from your project
|
|
41
|
+
9. Other built-in transformers like code block wrapping
|
|
42
|
+
10. `post` from addons and themes
|
|
43
|
+
11. `post` from your project
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Configure UnoCSS
|
|
2
|
+
|
|
3
|
+
<Environment type="node" />
|
|
4
|
+
|
|
5
|
+
[UnoCSS](https://unocss.dev) is now the default CSS framework for Slidev since v0.42.0. UnoCSS is a fast atomic CSS engine that has full flexibility and extensibility. Most of the Tailwind CSS classes are supported **out-of-box**, and you can also extend it with your own configurations.
|
|
6
|
+
|
|
7
|
+
By default, Slidev enables the following presets out-of-box:
|
|
8
|
+
|
|
9
|
+
- [@unocss/preset-wind3](https://unocss.dev/presets/wind3) - Tailwind / Windi CSS compatible utilities
|
|
10
|
+
- [@unocss/preset-attributify](https://unocss.dev/presets/attributify) - Attributify mode
|
|
11
|
+
- [@unocss/preset-icons](https://unocss.dev/presets/icons) - Use any icons as class
|
|
12
|
+
- [@unocss/preset-web-fonts](https://unocss.dev/presets/web-fonts) - Use web fonts at ease
|
|
13
|
+
- [@unocss/transformer-directives](https://unocss.dev/transformers/directives) - Use `@apply` in CSS
|
|
14
|
+
|
|
15
|
+
Slidev also adds shortcuts as can be seen in its [source code](https://github.com/slidevjs/slidev/blob/main/packages/client/uno.config.ts).
|
|
16
|
+
|
|
17
|
+
You can therefore style your content the way you want. For example:
|
|
18
|
+
|
|
19
|
+
```html
|
|
20
|
+
<div class="grid pt-4 gap-4 grid-cols-[100px,1fr]">
|
|
21
|
+
|
|
22
|
+
### Name
|
|
23
|
+
|
|
24
|
+
- Item 1
|
|
25
|
+
- Item 2
|
|
26
|
+
|
|
27
|
+
</div>
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Configurations
|
|
31
|
+
|
|
32
|
+
You can create `uno.config.ts` under the root of your project to extend the builtin configurations
|
|
33
|
+
|
|
34
|
+
```ts twoslash
|
|
35
|
+
import { defineConfig } from 'unocss'
|
|
36
|
+
|
|
37
|
+
export default defineConfig({
|
|
38
|
+
shortcuts: {
|
|
39
|
+
// custom the default background
|
|
40
|
+
'bg-main': 'bg-white text-[#181818] dark:(bg-[#121212] text-[#ddd])',
|
|
41
|
+
},
|
|
42
|
+
// ...
|
|
43
|
+
})
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Learn more about [UnoCSS configurations](https://unocss.dev/guide/config-file)
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# Configure Vite and Plugins
|
|
2
|
+
|
|
3
|
+
<Environment type="node" />
|
|
4
|
+
|
|
5
|
+
Slidev is powered by [Vite](https://vitejs.dev/) under the hood. This means you can leverage Vite's great plugin system to customize your slides even further.
|
|
6
|
+
|
|
7
|
+
The `vite.config.ts` will be respected if you have one, and will be merged with the Vite config provided by Slidev, your theme and the addons.
|
|
8
|
+
|
|
9
|
+
## Configure Internal Plugins
|
|
10
|
+
|
|
11
|
+
Slidev internally adds the following plugins to Vite:
|
|
12
|
+
|
|
13
|
+
- [@vitejs/plugin-vue](https://github.com/vitejs/vite-plugin-vue)
|
|
14
|
+
- [unplugin-vue-components](https://github.com/unplugin/unplugin-vue-components)
|
|
15
|
+
- [unplugin-icons](https://github.com/unplugin/unplugin-icons)
|
|
16
|
+
- [vite-plugin-vue-markdown](https://github.com/unplugin/unplugin-vue-markdown)
|
|
17
|
+
- [vite-plugin-remote-assets](https://github.com/antfu/vite-plugin-remote-assets)
|
|
18
|
+
- [unocss/vite](https://github.com/unocss/unocss/tree/main/packages/vite)
|
|
19
|
+
|
|
20
|
+
To configure the built-in plugins listed above, create a `vite.config.ts` with the following content. Please note that Slidev has some [default configurations](https://github.com/slidevjs/slidev/blob/main/packages/slidev/node/vite/index.ts) for those plugins, this usage will override some of them, which may potentially cause the app to break. Please treat this as **an advanced feature**, and make sure you know what you are doing before moving on.
|
|
21
|
+
|
|
22
|
+
<!-- eslint-disable import/first -->
|
|
23
|
+
|
|
24
|
+
```ts twoslash
|
|
25
|
+
/// <reference types="@slidev/types" />
|
|
26
|
+
import type MarkdownIt from 'markdown-it'
|
|
27
|
+
declare const MyPlugin: (md: any) => void
|
|
28
|
+
// ---cut---
|
|
29
|
+
import { defineConfig } from 'vite'
|
|
30
|
+
|
|
31
|
+
export default defineConfig({
|
|
32
|
+
slidev: {
|
|
33
|
+
vue: {
|
|
34
|
+
/* vue options */
|
|
35
|
+
},
|
|
36
|
+
markdown: {
|
|
37
|
+
/* markdown-it options */
|
|
38
|
+
markdownItSetup(md) {
|
|
39
|
+
/* custom markdown-it plugins */
|
|
40
|
+
md.use(MyPlugin)
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
/* options for other plugins */
|
|
44
|
+
},
|
|
45
|
+
})
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
See the [type declarations](https://github.com/slidevjs/slidev/blob/main/packages/types/src/vite.ts#L11) for more options.
|
|
49
|
+
|
|
50
|
+
::: warning
|
|
51
|
+
It is not allowed to re-add plugins that has been used internally be Slidev. For example, instead of
|
|
52
|
+
|
|
53
|
+
```ts twoslash
|
|
54
|
+
import Vue from '@vitejs/plugin-vue'
|
|
55
|
+
import { defineConfig } from 'vite'
|
|
56
|
+
|
|
57
|
+
export default defineConfig({
|
|
58
|
+
plugins: [
|
|
59
|
+
Vue({
|
|
60
|
+
/* vue options */
|
|
61
|
+
})
|
|
62
|
+
],
|
|
63
|
+
})
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Please pass the Vue options to the `slidev.vue` field as described above
|
|
67
|
+
:::
|
|
68
|
+
|
|
69
|
+
## Add Custom Plugins based on Slide data
|
|
70
|
+
|
|
71
|
+
Usually you can add Vite plugins into your `vite.config.ts` (see above).
|
|
72
|
+
However, if you want to add plugins based on the slide data, you need to add a `./setup/vite-plugins.ts` with the following content:
|
|
73
|
+
|
|
74
|
+
```ts twoslash
|
|
75
|
+
import { defineVitePluginsSetup } from '@slidev/types'
|
|
76
|
+
|
|
77
|
+
export default defineVitePluginsSetup((options) => {
|
|
78
|
+
return [
|
|
79
|
+
// Your plugins here
|
|
80
|
+
// Slide data is available as options.data.slides
|
|
81
|
+
]
|
|
82
|
+
})
|
|
83
|
+
```
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Configure Vue App
|
|
2
|
+
|
|
3
|
+
<Environment type="client" />
|
|
4
|
+
|
|
5
|
+
Slidev uses [Vue 3](https://v3.vuejs.org/) to render the application on the client side. You can extend the app to add custom plugins or configurations.
|
|
6
|
+
|
|
7
|
+
Create `./setup/main.ts` with the following content:
|
|
8
|
+
|
|
9
|
+
<!-- eslint-disable import/first -->
|
|
10
|
+
|
|
11
|
+
```ts twoslash
|
|
12
|
+
import type { Plugin } from 'vue'
|
|
13
|
+
declare const YourPlugin: Plugin
|
|
14
|
+
// ---cut---
|
|
15
|
+
import { defineAppSetup } from '@slidev/types'
|
|
16
|
+
|
|
17
|
+
export default defineAppSetup(({ app, router }) => {
|
|
18
|
+
// Vue App
|
|
19
|
+
app.use(YourPlugin)
|
|
20
|
+
})
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
This can also be used as the main entrance of your Slidev app to do some initializations before the app starts.
|
|
24
|
+
|
|
25
|
+
Learn more: [Vue Application API](https://v3.vuejs.org/api/application-api.html#component).
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# Directory Structure
|
|
2
|
+
|
|
3
|
+
Slidev employs some directory structure conventions to minimize the configuration surface and to make the functionality extensions flexible and intuitive.
|
|
4
|
+
|
|
5
|
+
The conventional directory structure is:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
your-slidev/
|
|
9
|
+
├── components/ # custom components
|
|
10
|
+
├── layouts/ # custom layouts
|
|
11
|
+
├── public/ # static assets
|
|
12
|
+
├── setup/ # custom setup / hooks
|
|
13
|
+
├── snippets/ # code snippets
|
|
14
|
+
├── styles/ # custom style
|
|
15
|
+
├── index.html # injections to index.html
|
|
16
|
+
├── slides.md # the main slides entry
|
|
17
|
+
└── vite.config.ts # extending vite config
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
All of them are optional.
|
|
21
|
+
|
|
22
|
+
## Components
|
|
23
|
+
|
|
24
|
+
Pattern: `./components/*.{vue,js,ts,jsx,tsx,md}`
|
|
25
|
+
|
|
26
|
+
<LinkCard link="guide/component" />
|
|
27
|
+
|
|
28
|
+
## Layouts
|
|
29
|
+
|
|
30
|
+
Pattern: `./layouts/*.{vue,js,ts,jsx,tsx}`
|
|
31
|
+
|
|
32
|
+
<LinkCard link="guide/layout" />
|
|
33
|
+
|
|
34
|
+
## Public
|
|
35
|
+
|
|
36
|
+
Pattern: `./public/*`
|
|
37
|
+
|
|
38
|
+
Assets in this directory will be served at root path `/` during dev, and copied to the root of the dist directory as-is. Read more about [Assets Handling](../guide/faq#assets-handling).
|
|
39
|
+
|
|
40
|
+
## Style
|
|
41
|
+
|
|
42
|
+
Pattern: `./style.css` | `./styles/index.{css,js,ts}`
|
|
43
|
+
|
|
44
|
+
Files following this convention will be injected to the App root. If you need to import multiple CSS entries, you can create the following structure and manage the import order yourself.
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
your-slidev/
|
|
48
|
+
├── ...
|
|
49
|
+
└── styles/
|
|
50
|
+
├── index.ts
|
|
51
|
+
├── base.css
|
|
52
|
+
├── code.css
|
|
53
|
+
└── layouts.css
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
// styles/index.ts
|
|
58
|
+
|
|
59
|
+
import './base.css'
|
|
60
|
+
import './code.css'
|
|
61
|
+
import './layouts.css'
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Styles will be processed by [UnoCSS](https://unocss.dev/) and [PostCSS](https://postcss.org/), so you can use CSS nesting and [at-directives](https://unocss.dev/transformers/directives#apply) and Nested CSS out-of-box. For example:
|
|
65
|
+
|
|
66
|
+
<!-- eslint-skip -->
|
|
67
|
+
|
|
68
|
+
```css
|
|
69
|
+
.slidev-layout {
|
|
70
|
+
--uno: px-14 py-10 text-[1.1rem];
|
|
71
|
+
|
|
72
|
+
h1, h2, h3, h4, p, div {
|
|
73
|
+
--uno: select-none;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
pre, code {
|
|
77
|
+
--uno: select-text;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
a {
|
|
81
|
+
color: theme('colors.primary');
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Learn more about the syntax [here](https://unocss.dev/transformers/directives#apply).
|
|
87
|
+
|
|
88
|
+
## `index.html`
|
|
89
|
+
|
|
90
|
+
Pattern: `index.html`
|
|
91
|
+
|
|
92
|
+
The `index.html` provides the ability to inject meta tags and/or scripts to the main `index.html`
|
|
93
|
+
|
|
94
|
+
For example, for the following custom `index.html`:
|
|
95
|
+
|
|
96
|
+
```html
|
|
97
|
+
<!-- ./index.html -->
|
|
98
|
+
<head>
|
|
99
|
+
<link rel="preconnect" href="https://fonts.gstatic.com">
|
|
100
|
+
<link href="https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;600&family=Nunito+Sans:wght@200;400;600&display=swap" rel="stylesheet">
|
|
101
|
+
</head>
|
|
102
|
+
|
|
103
|
+
<body>
|
|
104
|
+
<script src="./your-scripts"></script>
|
|
105
|
+
</body>
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
The final hosted `index.html` will be:
|
|
109
|
+
|
|
110
|
+
```html
|
|
111
|
+
<!DOCTYPE html>
|
|
112
|
+
<html lang="en">
|
|
113
|
+
<head>
|
|
114
|
+
<meta charset="UTF-8">
|
|
115
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
116
|
+
<link rel="icon" type="image/png" href="https://cdn.jsdelivr.net/gh/slidevjs/slidev/assets/favicon.png">
|
|
117
|
+
<!-- injected head -->
|
|
118
|
+
<link rel="preconnect" href="https://fonts.gstatic.com">
|
|
119
|
+
<link href="https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;600&family=Nunito+Sans:wght@200;400;600&display=swap" rel="stylesheet">
|
|
120
|
+
</head>
|
|
121
|
+
<body>
|
|
122
|
+
<div id="app"></div>
|
|
123
|
+
<script type="module" src="__ENTRY__"></script>
|
|
124
|
+
<!-- injected body -->
|
|
125
|
+
<script src="./your-scripts"></script>
|
|
126
|
+
</body>
|
|
127
|
+
</html>
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Global Layers
|
|
131
|
+
|
|
132
|
+
Pattern: `global-top.vue` | `global-bottom.vue` | `custom-nav-controls.vue` | `slide-top.vue` | `slide-bottom.vue`
|
|
133
|
+
|
|
134
|
+
<LinkCard link="features/global-layers" />
|