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'] const supportedConfigExtensions = ['js', 'ts', 'cjs', 'mjs', 'cts', 'mts']
async function resolveUserConfig( export async function resolveUserConfig(
root: string, root: string,
command: 'serve' | 'build', command: 'serve' | 'build',
mode: string mode: string

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

Loading…
Cancel
Save