From f9e4cfe1edc76ff6a14c834067b26d5feca9651f Mon Sep 17 00:00:00 2001 From: FinalAshen <819712530@qq.com> Date: Thu, 28 Dec 2023 18:48:54 +0800 Subject: [PATCH] fix: resovedUrls is null after server restart --- packages/vite/src/node/server/index.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/vite/src/node/server/index.ts b/packages/vite/src/node/server/index.ts index bec44dafb25910..a4a949a7add019 100644 --- a/packages/vite/src/node/server/index.ts +++ b/packages/vite/src/node/server/index.ts @@ -430,7 +430,9 @@ export async function _createServer( const devHtmlTransformFn = createDevHtmlTransformFn(config) - let server: ViteDevServer = { + let server = {} as ViteDevServer + + let initServerParameters: ViteDevServer = { config, middlewares, httpServer, @@ -611,7 +613,7 @@ export async function _createServer( _setInternalServer(_server: ViteDevServer) { // Rebind internal the server variable so functions reference the user // server instance after a restart - server = _server + initServerParameters = _server }, _restartPromise: null, _importGlobMap: new Map(), @@ -621,6 +623,16 @@ export async function _createServer( _shortcutsOptions: undefined, } + server = new Proxy(initServerParameters, { + get: (_, property: keyof ViteDevServer) => { + return initServerParameters[property] + }, + set: (_, property: keyof ViteDevServer, value: never) => { + initServerParameters[property] = value + return true + }, + }) + if (!middlewareMode) { exitProcess = async () => { try { @@ -842,7 +854,7 @@ export async function _createServer( await initServer() } - return server + return initServerParameters } async function startServer(