Skip to content

Commit 80cec96

Browse files
feat(vitrify): merge dev server config into baseConfig
1 parent 433ead7 commit 80cec96

File tree

3 files changed

+43
-39
lines changed

3 files changed

+43
-39
lines changed

.changeset/swift-otters-share.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'vitrify': minor
3+
---
4+
5+
feat(vitrify): merge dev server config into baseConfig

packages/vitrify/src/node/bin/dev.ts

Lines changed: 15 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ export async function createVitrifyDevServer({
4949
'../app-urls.js'
5050
)
5151

52-
const cliDir = getCliDir()
53-
5452
if (!appDir) appDir = getAppDir()
5553
let config: InlineConfig = {}
5654
let ssrMode: 'server' | 'fastify' | undefined
@@ -66,52 +64,32 @@ export async function createVitrifyDevServer({
6664
base
6765
})
6866

69-
config.logLevel = logLevel
70-
71-
config.define = {
72-
...config.define,
73-
__HOST__: `'${host}'`
74-
}
75-
7667
const wsPort = await getFirstOpenPort(24678)
7768
if (config.server?.https) {
7869
exitLogs.push(
7970
`[warning] HTTPS mode enabled. Visit https://{hostname}:${wsPort} to enable a security exception for HMR.`
8071
)
8172
}
82-
config.server = {
83-
https: config.server?.https,
84-
hmr: {
85-
protocol: config.server?.https ? 'wss' : 'ws',
86-
port: wsPort
87-
},
88-
port,
89-
// middlewareMode: mode === 'ssr' ? 'ssr' : undefined,
90-
middlewareMode: ssr ? true : false,
91-
fs: {
92-
strict: false, // https://github.com/vitejs/vite/issues/8175
93-
allow: [
94-
searchForWorkspaceRoot(process.cwd()),
95-
searchForWorkspaceRoot(fileURLToPath(appDir)),
96-
searchForWorkspaceRoot(fileURLToPath(cliDir)),
97-
fileURLToPath(appDir)
98-
]
99-
},
100-
watch: {
101-
// During tests we edit the files too fast and sometimes chokidar
102-
// misses change events, so enforce polling for consistency
103-
usePolling: true,
104-
interval: 100
105-
},
106-
host
107-
}
108-
if (ssr) config.appType = 'custom'
10973

11074
const vitrifyDevServer = await (
11175
await import('vite')
11276
).createServer({
11377
configFile: false,
114-
...config
78+
...config,
79+
logLevel,
80+
define: {
81+
...config.define,
82+
__HOST__: `'${host}'`
83+
},
84+
server: {
85+
...config.server,
86+
host,
87+
port,
88+
hmr: {
89+
protocol: config.server?.https ? 'wss' : 'ws',
90+
port: wsPort
91+
}
92+
}
11593
})
11694

11795
return vitrifyDevServer

packages/vitrify/src/node/index.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { addOrReplaceTitle, appendToBody } from './helpers/utils.js'
3737
import Components from 'unplugin-vue-components/vite'
3838
import { VitePWA } from 'vite-plugin-pwa'
3939
import UnoCSS from 'unocss/vite'
40+
import { searchForWorkspaceRoot } from 'vite'
4041

4142
const internalServerModules = [
4243
'util',
@@ -652,6 +653,7 @@ export const baseConfig = async ({
652653

653654
const config = {
654655
root: fileURLToPath(appDir),
656+
appType: ssr ? 'custom' : 'spa',
655657
publicDir: fileURLToPath(publicDir),
656658
base,
657659
envDir: fileURLToPath(appDir),
@@ -689,8 +691,27 @@ export const baseConfig = async ({
689691
__BASE_URL__: `'${base}'`,
690692
__IS_PWA__: `${isPwa}`
691693
},
692-
environments: {
693-
server: ssr ? {} : undefined
694+
// environments: {
695+
// },
696+
server: {
697+
https: vitrifyConfig.server?.https,
698+
// middlewareMode: mode === 'ssr' ? 'ssr' : undefined,
699+
middlewareMode: ssr ? true : false,
700+
fs: {
701+
strict: false, // https://github.com/vitejs/vite/issues/8175
702+
allow: [
703+
searchForWorkspaceRoot(process.cwd()),
704+
searchForWorkspaceRoot(fileURLToPath(appDir)),
705+
searchForWorkspaceRoot(fileURLToPath(cliDir)),
706+
fileURLToPath(appDir)
707+
]
708+
},
709+
watch: {
710+
// During tests we edit the files too fast and sometimes chokidar
711+
// misses change events, so enforce polling for consistency
712+
usePolling: true,
713+
interval: 100
714+
}
694715
}
695716
} as VitrifyConfig
696717

0 commit comments

Comments
 (0)