You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: custom/config-monaco.md
+31-58Lines changed: 31 additions & 58 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ Learn more about [configuring Monaco](https://github.com/Microsoft/monaco-editor
19
19
To use Monaco in your slides, simply append `{monaco}` to your code snippets:
20
20
21
21
~~~md
22
-
```js
22
+
```js {monaco} // [!code ++]
23
23
const count = ref(1)
24
24
const plusOne = computed(() => count.value + 1)
25
25
@@ -29,30 +29,7 @@ plusOne.value++ // error
29
29
```
30
30
~~~
31
31
32
-
To
33
-
34
-
~~~md
35
-
```js {monaco}
36
-
const count = ref(1)
37
-
const plusOne = computed(() => count.value + 1)
38
-
39
-
console.log(plusOne.value) // 2
40
-
41
-
plusOne.value++ // error
42
-
```
43
-
~~~
44
-
45
-
## Exporting
46
-
47
-
By default, Monaco will ONLY work on `dev` mode. If you would like to have it available in the exported SPA, configure it in your frontmatter:
48
-
49
-
```yaml
50
-
---
51
-
monaco: true # default "dev"
52
-
---
53
-
```
54
-
55
-
## Types Auto Installing
32
+
## TypeScript Types
56
33
57
34
When use TypeScript with Monaco, types for dependencies will be installed to the client-side automatically.
58
35
@@ -65,49 +42,35 @@ const counter = ref(0)
65
42
```
66
43
~~~
67
44
68
-
In the example above, make sure `vue` and `@vueuse/core` are installed locally as dependencies / devDependencies, Slidev will handle the rest to get the types working for the editor automatically!
45
+
In the example above, make sure `vue` and `@vueuse/core` are installed locally as dependencies / devDependencies, Slidev will handle the rest to get the types working for the editor automatically. When deploy as SPA, those types will also be bundled for static hosting.
69
46
70
-
## Configure Themes
71
-
72
-
The theme is controlled by Slidev based on the light/dark theme. If you want to customize it, you can pass the theme id to the setup function:
47
+
### Additional Types
73
48
74
-
```ts
75
-
// ./setup/monaco.ts
76
-
import { defineMonacoSetup } from'@slidev/types'
49
+
Slidev will scan all the monaco codeblocks in your slides and import the types for those used libraries for you. In case it missed some, you can explicitly specify extra packages to import the types for:
77
50
78
-
exportdefaultdefineMonacoSetup(() => {
79
-
return {
80
-
theme: {
81
-
dark: 'vs-dark',
82
-
light: 'vs',
83
-
},
84
-
}
85
-
})
51
+
```md
52
+
---
53
+
monacoTypesAdditionalPackages:
54
+
- lodash-es
55
+
- foo
56
+
---
86
57
```
87
58
88
-
If you want to load custom themes:
59
+
### Auto Type Acquisition
89
60
90
-
```ts
91
-
import { defineMonacoSetup } from'@slidev/types'
61
+
You can optionally switch to load types from CDN by setting the following headmatter:
This feature is powered by [`@typescript/ata`](https://github.com/microsoft/TypeScript-Website/tree/v2/packages/ata) and runs completely on the client-side.
100
70
101
-
return {
102
-
theme: {
103
-
light: 'vitesse-light',
104
-
dark: 'vitesse-dark',
105
-
},
106
-
}
107
-
})
108
-
```
71
+
## Configure Themes
109
72
110
-
> If you are creating a theme for Slidev, use dynamic `import()` inside the setup function to get better tree-shaking and code-splitting results.
73
+
Since v0.48.0, Monaco will reuse the Shiki theme you configured in [Shiki's setup file](/custom/highlighters#configure-shiki), powered by [`@shikijs/monaco`](https://shiki.style/packages/monaco). You don't need to worry about it anymore and it will have a consistent style with the rest of your code blocks.
Since v0.48.0, Monaco editor is enabled by default and only be bundled when you use it. If you want to disable it, you can set `monaco` to `false` in the frontmatter of your slide:
105
+
106
+
```yaml
107
+
---
108
+
monaco: false # can also be `dev` or `build` tp conditionally enable it
0 commit comments