-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
server.ts
34 lines (30 loc) · 953 Bytes
/
server.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { join } from 'path'
import { createServer as createViteServer, InlineConfig, mergeConfig, resolveConfig } from 'vite'
import { ResolvedSlidevOptions, SlidevServerOptions } from './options'
import { ViteSlidevPlugin } from './plugins/preset'
export async function createServer(
options: ResolvedSlidevOptions,
viteConfig: InlineConfig = {},
serverOptions: SlidevServerOptions = {},
) {
const rawConfig = await resolveConfig({}, 'serve')
const pluginOptions = rawConfig.slidev || {}
// default open editor to code, #312
process.env.EDITOR = process.env.EDITOR || 'code'
const server = await createViteServer(
mergeConfig(
viteConfig,
<InlineConfig>({
optimizeDeps: {
entries: [
join(options.clientRoot, 'main.ts'),
],
},
plugins: [
await ViteSlidevPlugin(options, pluginOptions, serverOptions),
],
}),
),
)
return server
}