mirror of
https://github.com/vitejs/vite.git
synced 2024-11-22 07:09:05 +00:00
fix: restart optimize (#7004)
This commit is contained in:
parent
ce07a0ad6a
commit
47fbe29a97
@ -10,7 +10,7 @@ import chokidar from 'chokidar'
|
||||
import type { CommonServerOptions } from '../http'
|
||||
import { resolveHttpsConfig, resolveHttpServer, httpServerStart } from '../http'
|
||||
import type { InlineConfig, ResolvedConfig } from '../config'
|
||||
import { resolveConfig } from '../config'
|
||||
import { mergeConfig, resolveConfig } from '../config'
|
||||
import type { PluginContainer } from './pluginContainer'
|
||||
import { createPluginContainer } from './pluginContainer'
|
||||
import type { FSWatcher, WatchOptions } from 'types/chokidar'
|
||||
@ -409,7 +409,7 @@ export async function createServer(
|
||||
throw new Error('cannot print server URLs in middleware mode.')
|
||||
}
|
||||
},
|
||||
async restart(forceOptimize: boolean) {
|
||||
async restart(forceOptimize?: boolean) {
|
||||
if (!server._restartPromise) {
|
||||
server._forceOptimizeOnRestart = !!forceOptimize
|
||||
server._restartPromise = restartServer(server).finally(() => {
|
||||
@ -574,7 +574,7 @@ export async function createServer(
|
||||
try {
|
||||
server._optimizeDepsMetadata = await optimizeDeps(
|
||||
config,
|
||||
config.server.force || server._forceOptimizeOnRestart
|
||||
config.server.force
|
||||
)
|
||||
} finally {
|
||||
server._isRunningOptimizer = false
|
||||
@ -743,9 +743,18 @@ async function restartServer(server: ViteDevServer) {
|
||||
|
||||
await server.close()
|
||||
|
||||
let inlineConfig = server.config.inlineConfig
|
||||
if (server._forceOptimizeOnRestart) {
|
||||
inlineConfig = mergeConfig(inlineConfig, {
|
||||
server: {
|
||||
force: true
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
let newServer = null
|
||||
try {
|
||||
newServer = await createServer(server.config.inlineConfig)
|
||||
newServer = await createServer(inlineConfig)
|
||||
} catch (err: any) {
|
||||
server.config.logger.error(err.message, {
|
||||
timestamp: true
|
||||
@ -754,7 +763,11 @@ async function restartServer(server: ViteDevServer) {
|
||||
}
|
||||
|
||||
for (const key in newServer) {
|
||||
if (key !== 'app') {
|
||||
if (key === '_restartPromise') {
|
||||
// prevent new server `restart` function from calling
|
||||
// @ts-ignore
|
||||
newServer[key] = server[key]
|
||||
} else if (key !== 'app') {
|
||||
// @ts-ignore
|
||||
server[key] = newServer[key]
|
||||
}
|
||||
@ -774,4 +787,7 @@ async function restartServer(server: ViteDevServer) {
|
||||
} else {
|
||||
logger.info('server restarted.', { timestamp: true })
|
||||
}
|
||||
|
||||
// new server (the current server) can restart now
|
||||
newServer._restartPromise = null
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user