Skip to content

Commit d85cd98

Browse files
committed
docs: update docs about Monaco
1 parent d90cc87 commit d85cd98

File tree

2 files changed

+32
-59
lines changed

2 files changed

+32
-59
lines changed

.vitepress/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { DefaultTheme } from 'vitepress'
22
import { defineConfig } from 'vitepress'
33
import { transformerTwoslash } from '@shikijs/vitepress-twoslash'
44

5-
const CURRENT_VERSION = '0.48.0-beta.2'
5+
const CURRENT_VERSION = '0.48.0-beta.22'
66

77
const Guide: DefaultTheme.NavItemWithLink[] = [
88
{

custom/config-monaco.md

Lines changed: 31 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Learn more about [configuring Monaco](https://github.com/Microsoft/monaco-editor
1919
To use Monaco in your slides, simply append `{monaco}` to your code snippets:
2020

2121
~~~md
22-
```js
22+
```js {monaco} // [!code ++]
2323
const count = ref(1)
2424
const plusOne = computed(() => count.value + 1)
2525

@@ -29,30 +29,7 @@ plusOne.value++ // error
2929
```
3030
~~~
3131

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
5633

5734
When use TypeScript with Monaco, types for dependencies will be installed to the client-side automatically.
5835

@@ -65,49 +42,35 @@ const counter = ref(0)
6542
```
6643
~~~
6744

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.
6946

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
7348

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:
7750

78-
export default defineMonacoSetup(() => {
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+
---
8657
```
8758

88-
If you want to load custom themes:
59+
### Auto Type Acquisition
8960

90-
```ts
91-
import { defineMonacoSetup } from '@slidev/types'
61+
You can optionally switch to load types from CDN by setting the following headmatter:
9262

93-
// change to your themes
94-
import dark from 'theme-vitesse/themes/vitesse-dark.json'
95-
import light from 'theme-vitesse/themes/vitesse-light.json'
63+
```md
64+
---
65+
monacoTypesSource: ata
66+
---
67+
```
9668

97-
export default defineMonacoSetup((monaco) => {
98-
monaco.editor.defineTheme('vitesse-light', light as any)
99-
monaco.editor.defineTheme('vitesse-dark', dark as any)
69+
This feature is powered by [`@typescript/ata`](https://github.com/microsoft/TypeScript-Website/tree/v2/packages/ata) and runs completely on the client-side.
10070

101-
return {
102-
theme: {
103-
light: 'vitesse-light',
104-
dark: 'vitesse-dark',
105-
},
106-
}
107-
})
108-
```
71+
## Configure Themes
10972

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.
11174

11275
## Configure the Editor
11376

@@ -135,3 +98,13 @@ export default defineMonacoSetup(() => {
13598
}
13699
})
137100
```
101+
102+
## Disabling
103+
104+
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
109+
---
110+
```

0 commit comments

Comments
 (0)