Skip to content
This repository was archived by the owner on Aug 16, 2024. It is now read-only.

Commit 73991e7

Browse files
committed
feat: allow running non ssr in dev
1 parent 0cd73e6 commit 73991e7

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

src/cli.ts

+24-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import mri from 'mri'
22
import { loadConfig } from 'c12'
3-
import { argv } from 'node:process'
3+
import { mergeConfig, createServer } from 'vite'
4+
import vue from '@vitejs/plugin-vue'
5+
import { argv, cwd } from 'node:process'
46
import { VueSsrConfig } from './types'
57
import { dev } from './node/dev'
68
import { build } from './node/build'
79
import { start } from './node/start'
10+
import { vueSsrPlugin } from './vue/plugin'
811

912
const args = mri(argv.slice(2));
1013
const command = args._[0];
@@ -21,9 +24,24 @@ if (command === 'build') {
2124
host ?? config?.hostname ?? 'localhost'
2225
)
2326
} else {
24-
await dev({
25-
port: port ?? config?.port ?? 5173,
26-
hostname: host ?? config?.hostname ?? 'localhost',
27-
viteConfig: config?.vite,
28-
})
27+
if (ssr !== undefined ? /^true$/i.test(ssr) : config?.ssr ?? true) {
28+
await dev({
29+
port: port ?? config?.port ?? 5173,
30+
hostname: host ?? config?.hostname ?? 'localhost',
31+
viteConfig: config?.vite,
32+
})
33+
} else {
34+
const server = await createServer(mergeConfig({
35+
configFile: false,
36+
base: '/',
37+
root: cwd(),
38+
plugins: [vue(), vueSsrPlugin()],
39+
define: {
40+
__SSR_APP__: false,
41+
},
42+
}, config?.vite ?? {}))
43+
await server.listen()
44+
45+
server.printUrls()
46+
}
2947
}

0 commit comments

Comments
 (0)