Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(hmr): dev mode reduce unnecessary restart #14426

Merged
merged 3 commits into from
Sep 28, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/vite/src/node/server/hmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ export function getShortName(file: string, root: string): string {
: file
}

function changeEnvShouldRestart(mode: string, fileName: string) {
if (fileName === '.env' || fileName === '.env.local') {
return true
}
return fileName === `.env.${mode}` || fileName === `.env.${mode}.local`
}

export async function handleHMRUpdate(
file: string,
server: ViteDevServer,
Expand All @@ -62,9 +69,10 @@ export async function handleHMRUpdate(
const isConfigDependency = config.configFileDependencies.some(
(name) => file === name,
)

const isEnv =
config.inlineConfig.envFile !== false &&
(fileName === '.env' || fileName.startsWith('.env.'))
changeEnvShouldRestart(config.mode, fileName)
if (isConfig || isConfigDependency || isEnv) {
// auto restart server
debugHmr?.(`[config change] ${colors.dim(shortFile)}`)
Expand Down