| 1 | import type { ArgumentsType } from '@antfu/utils' |
| 2 | import type Vue from '@vitejs/plugin-vue' |
| 3 | import type VueJsx from '@vitejs/plugin-vue-jsx' |
| 4 | import type { VitePluginConfig as UnoCSSConfig } from 'unocss/vite' |
| 5 | import type Icons from 'unplugin-icons/vite' |
| 6 | import type Components from 'unplugin-vue-components/vite' |
| 7 | import type Markdown from 'unplugin-vue-markdown/vite' |
| 8 | import type { UserConfigExport } from 'vite' |
| 9 | import type { ViteInspectOptions } from 'vite-plugin-inspect' |
| 10 | import type RemoteAssets from 'vite-plugin-remote-assets' |
| 11 | import type { ViteStaticCopyOptions } from 'vite-plugin-static-copy' |
| 12 | import type ServerRef from 'vite-plugin-vue-server-ref' |
| 13 | |
| 14 | export interface SlidevPluginOptions { |
| 15 | vue?: ArgumentsType<typeof Vue>[0] |
| 16 | vuejsx?: ArgumentsType<typeof VueJsx>[0] |
| 17 | markdown?: ArgumentsType<typeof Markdown>[0] |
| 18 | components?: ArgumentsType<typeof Components>[0] |
| 19 | icons?: ArgumentsType<typeof Icons>[0] |
| 20 | remoteAssets?: ArgumentsType<typeof RemoteAssets>[0] |
| 21 | serverRef?: ArgumentsType<typeof ServerRef>[0] |
| 22 | unocss?: UnoCSSConfig |
| 23 | staticCopy?: ViteStaticCopyOptions |
| 24 | inspect?: ViteInspectOptions |
| 25 | } |
| 26 | |
| 27 | // extend vite.config.ts |
| 28 | declare module 'vite' { |
| 29 | interface UserConfig { |
| 30 | /** |
| 31 | * Custom internal plugin options for Slidev (advanced) |
| 32 | * |
| 33 | * See https://github.com/slidevjs/slidev/blob/main/packages/slidev/node/options.ts#L50 |
| 34 | */ |
| 35 | slidev?: SlidevPluginOptions |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Drop-in replacement for Vite's `defineConfig` in a Slidev project. |
| 41 | * |
| 42 | * Vite's own `defineConfig` does not know about the `slidev` field above |
| 43 | * unless `@slidev/types` happens to be in the TypeScript program already. |
| 44 | * Importing this helper pulls the declaration in, so the `slidev` field is |
| 45 | * always recognized and type checked. |
| 46 | * |
| 47 | * @example |
| 48 | * ```ts |
| 49 | * import { defineViteConfig } from '@slidev/types' |
| 50 | * |
| 51 | * export default defineViteConfig({ |
| 52 | * slidev: { |
| 53 | * vue: { ... }, |
| 54 | * }, |
| 55 | * }) |
| 56 | * ``` |
| 57 | */ |
| 58 | export function defineViteConfig<T extends UserConfigExport>(config: T): T { |
| 59 | return config |
| 60 | } |
| 61 |