From 9ac63b1320ca929010a9cfd78e3c1a7797bd3a80 Mon Sep 17 00:00:00 2001 From: csr632 <632882184@qq.com> Date: Thu, 28 May 2020 21:31:34 +0800 Subject: [PATCH] fix: import.meta.hot should be injected before first `if (import.meta.hot)` (#285) Fix: https://github.com/vitejs/vite/issues/282 --- src/node/server/serverPluginHmr.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/node/server/serverPluginHmr.ts b/src/node/server/serverPluginHmr.ts index 1ea4d7113f947f..81936a6650d614 100644 --- a/src/node/server/serverPluginHmr.ts +++ b/src/node/server/serverPluginHmr.ts @@ -399,7 +399,8 @@ export function rewriteFileWithHMR( // if (import.meta.hot) ... if (node.type === 'IfStatement') { const isDevBlock = isMetaHot(node.test) - if (isDevBlock) { + if (isDevBlock && !importMetaConditional) { + // remember the first occurence of `if (import.meta.hot)` importMetaConditional = node } if (node.consequent.type === 'BlockStatement') {