fix: make config hmr work in window (#364)

pull/421/head
CHOYSEN 3 years ago committed by GitHub
parent 49ddb1f120
commit 58663bbd02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -3,6 +3,7 @@ import fs from 'fs-extra'
import chalk from 'chalk' import chalk from 'chalk'
import globby from 'globby' import globby from 'globby'
import { import {
normalizePath,
AliasOptions, AliasOptions,
UserConfig as ViteConfig, UserConfig as ViteConfig,
mergeConfig as mergeViteConfig mergeConfig as mergeViteConfig
@ -75,7 +76,7 @@ export interface SiteConfig<ThemeConfig = any> {
} }
const resolve = (root: string, file: string) => const resolve = (root: string, file: string) =>
path.resolve(root, `.vitepress`, file) normalizePath(path.resolve(root, `.vitepress`, file))
export async function resolveConfig( export async function resolveConfig(
root: string = process.cwd() root: string = process.cwd()
@ -127,7 +128,7 @@ export async function resolveUserConfig(root: string): Promise<UserConfig> {
const configPath = resolve(root, 'config.js') const configPath = resolve(root, 'config.js')
const hasUserConfig = await fs.pathExists(configPath) const hasUserConfig = await fs.pathExists(configPath)
// always delete cache first before loading config // always delete cache first before loading config
delete require.cache[configPath] delete require.cache[require.resolve(configPath)]
const userConfig: RawConfigExports = hasUserConfig ? require(configPath) : {} const userConfig: RawConfigExports = hasUserConfig ? require(configPath) : {}
if (hasUserConfig) { if (hasUserConfig) {
debug(`loaded config at ${chalk.yellow(configPath)}`) debug(`loaded config at ${chalk.yellow(configPath)}`)

Loading…
Cancel
Save