Skip to content

Commit

Permalink
fix: keep process running when fail to load config in restarting serv…
Browse files Browse the repository at this point in the history
…er (#2510)

close #2496
  • Loading branch information
CHOYSEN authored Mar 15, 2021
1 parent 96ea9f4 commit b18af15
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/vite/src/node/server/hmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ModuleNode } from './moduleGraph'
import { Update } from 'types/hmrPayload'
import { CLIENT_DIR } from '../constants'
import { RollupError } from 'rollup'
import { prepareError } from './middlewares/error'
import match from 'minimatch'

export const debugHmr = createDebugger('vite:hmr')
Expand Down Expand Up @@ -410,9 +411,20 @@ async function readModifiedFile(file: string): Promise<string> {
}

async function restartServer(server: ViteDevServer) {
// @ts-ignore
global.__vite_start_time = Date.now()
let newServer = null
try {
newServer = await createServer(server.config.inlineConfig)
} catch (err) {
server.ws.send({
type: 'error',
err: prepareError(err)
})
return
}

await server.close()
;(global as any).__vite_start_time = Date.now()
const newServer = await createServer(server.config.inlineConfig)
for (const key in newServer) {
if (key !== 'app') {
// @ts-ignore
Expand Down

0 comments on commit b18af15

Please sign in to comment.