diff --git a/src/node/config.ts b/src/node/config.ts index 9a5c67e..215033b 100644 --- a/src/node/config.ts +++ b/src/node/config.ts @@ -13,10 +13,15 @@ export async function resolveConfig( command: 'serve' | 'build', mode: 'development' | 'production' ): Promise { - const [configPath, userConfig] = await resolveUserConfig(root, command, mode) + const [configPath, userConfig, userConfigDeps] = await resolveUserConfig( + root, + command, + mode + ) const siteConfig: SiteConfig = { root, configPath: configPath, + configDeps: userConfigDeps, siteData: resolveSiteData(userConfig as UserConfig), } console.log(siteConfig, 'siteConfig') @@ -31,20 +36,21 @@ export async function resolveUserConfig( // 1. 获取配置路径 支持js 和 ts 格式 const configPath = getUserConfigPath(root) // 2.解析配置文件 - const { config: rawConfig = {} as RawUserConfig } = await loadConfigFromFile( - { - command, - mode, - }, - configPath, - root - ) + const { config: rawConfig = {} as RawUserConfig, dependencies = [] } = + await loadConfigFromFile( + { + command, + mode, + }, + configPath, + root + ) if (rawConfig) { const config = typeof rawConfig === 'function' ? await rawConfig() : rawConfig - return [configPath, config] as const + return [configPath, config, dependencies] as const } - return [configPath, {} as UserConfig] as const + return [configPath, {} as UserConfig, dependencies] as const } export function resolveSiteData(userConfig: UserConfig): UserConfig { diff --git a/src/node/plugin-r-press/config.ts b/src/node/plugin-r-press/config.ts index 0807864..0dc793a 100644 --- a/src/node/plugin-r-press/config.ts +++ b/src/node/plugin-r-press/config.ts @@ -23,7 +23,7 @@ export function pluginConfig( } }, async handleHotUpdate(ctx) { - const customWatchedFiles = [config.configPath] + const customWatchedFiles = [config.configPath, ...config.configDeps] const include = (id: string) => customWatchedFiles.some((file) => id.includes(file)) diff --git a/src/shared/types/index.ts b/src/shared/types/index.ts index 98a6f7c..986fb52 100644 --- a/src/shared/types/index.ts +++ b/src/shared/types/index.ts @@ -4,6 +4,7 @@ import type { UserConfig as ViteUserConfig } from 'vite' export interface SiteConfig { root: string configPath: string + configDeps: string[] siteData: UserConfig }