| 1 | import type { ResolvedSlidevOptions, SlidevServerOptions } from '@slidev/types' |
| 2 | import type { InlineConfig } from 'vite' |
| 3 | import process from 'node:process' |
| 4 | import { join } from 'pathe' |
| 5 | import { createServer as createViteServer } from 'vite' |
| 6 | import { resolveViteConfigs } from './shared' |
| 7 | |
| 8 | export async function createServer( |
| 9 | options: ResolvedSlidevOptions, |
| 10 | viteConfig: InlineConfig = {}, |
| 11 | serverOptions?: SlidevServerOptions, |
| 12 | ) { |
| 13 | // default open editor to code, #312 |
| 14 | process.env.EDITOR = process.env.EDITOR || 'code' |
| 15 | |
| 16 | const inlineConfig = await resolveViteConfigs( |
| 17 | options, |
| 18 | { |
| 19 | optimizeDeps: { |
| 20 | entries: [ |
| 21 | join(options.clientRoot, 'main.ts'), |
| 22 | ], |
| 23 | }, |
| 24 | } satisfies InlineConfig, |
| 25 | viteConfig, |
| 26 | 'serve', |
| 27 | serverOptions, |
| 28 | ) |
| 29 | |
| 30 | return await createViteServer(inlineConfig) |
| 31 | } |
| 32 |