From 4958ce6c1bc24592e9b140062043a17a5046900f Mon Sep 17 00:00:00 2001 From: c0dedance <2627702283@qq.com> Date: Sun, 15 Oct 2023 20:41:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=BE=9D=E8=B5=96=E5=8F=98=E6=9B=B4=E8=BF=9B=E8=A1=8C=E7=83=AD?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/node/config.ts | 28 +++++++++++++++++----------- src/node/plugin-r-press/config.ts | 2 +- src/shared/types/index.ts | 1 + 3 files changed, 19 insertions(+), 12 deletions(-) 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 }