fix: gracefully handle config update with syntax error

close #2041
pull/2040/head
Evan You 2 years ago
parent 31b548c718
commit 470ce3d3f3

@ -296,7 +296,7 @@ export async function resolveConfig(
const supportedConfigExtensions = ['js', 'ts', 'cjs', 'mjs', 'cts', 'mts']
async function resolveUserConfig(
export async function resolveUserConfig(
root: string,
command: 'serve' | 'build',
mode: string

@ -15,7 +15,7 @@ import {
SITE_DATA_REQUEST_PATH,
resolveAliases
} from './alias'
import { resolvePages, type SiteConfig } from './config'
import { resolveUserConfig, resolvePages, type SiteConfig } from './config'
import { clearCache, createMarkdownToVueRenderFn } from './markdownToVue'
import type { PageDataPayload } from './shared'
import { staticDataPlugin } from './plugins/staticDataPlugin'
@ -316,14 +316,15 @@ export async function createVitePressPlugin(
),
{ clear: true, timestamp: true }
)
try {
clearCache()
await recreateServer?.()
await resolveUserConfig(siteConfig.root, 'serve', 'development')
} catch (err: any) {
siteConfig.logger.error(
`\n${c.red(`failed to restart server. error:`)}\n${err.stack}`
)
return
}
clearCache()
await recreateServer?.()
return
}

Loading…
Cancel
Save