返回 slidev
write-addon.md
根目录 / docs / guide / write-addon.md
1 # Writing Addons
2
3 > Please read <LinkInline link="guide/theme-addon" /> and <LinkInline link="guide/write-theme" /> first.
4
5 Each slides project can only have one theme, but can have multiple addons.
6
7 ## Capability
8
9 Theoretically, all the capabilities of a theme can be done in an addon. However, an addon is more like a plugin that extends the functionalities of Slidev.
10
11 It's recommended to implement one or more of the following points in an addon:
12
13 - Provide custom components
14 - Provide _new_ layouts
15 - Provide new code snippets
16 - Provide new code runners
17 - Configure tools like UnoCSS, Vite, etc.
18
19 However, the following points are **not** recommended to be done in an addon, and may be better [implemented as a theme](./write-theme):
20
21 - Wildcard global styles
22 - Overriding existing layouts
23 - Overriding configurations
24 - Other things that may be incompatible with the theme and other addons
25
26 An addon can also specify its required Slidev version in the same way as themes.
27
28 ## Previewing
29
30 The same as themes, you can preview your addon via a `./slides.md` like this:
31
32 ```md [slides.md]
33 ---
34 addons:
35 - ./
36 ---
37 ```
38
39 ## Publishing
40
41 When publishing the addon, non-JS files like `.vue` and `.ts` files can be published directly without compiling. Slidev will automatically compile them when using the addon.
42
43 Addons should follow the following conventions:
44
45 - Package name should start with `slidev-addon-`. For example, `slidev-addon-name` or `@scope/slidev-addon-name`
46 - Add `"slidev-addon"` and `"slidev"` in the `keywords` field of your `package.json`
47
48 Addons can be used locally without publishing to NPM. If your addon is only for personal use, you can simply use it as a local addon, or publish it as a private scoped package. However, it is recommended to publish it to the NPM registry if you want to share it with others.
49
49 lines MARKDOWN