Skip to content

Commit 4371853

Browse files
authored
perf: wrap dynamic import to skip analysis of dynamic imports (#80)
1 parent 14767fc commit 4371853

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ ${result.code}
112112
113113
window.$RefreshReg$ = prevRefreshReg;
114114
window.$RefreshSig$ = prevRefreshSig;
115-
import(/* @vite-ignore */ import.meta.url).then((currentExports) => {
115+
RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
116116
RefreshRuntime.registerExportsForReactRefresh("${id}", currentExports);
117117
import.meta.hot.accept((nextExports) => {
118118
if (!nextExports) return;

src/refresh-runtime.js

+4
Original file line numberDiff line numberDiff line change
@@ -612,5 +612,9 @@ function predicateOnExport(moduleExports, predicate) {
612612
return true;
613613
}
614614

615+
// Hides vite-ignored dynamic import so that Vite can skip analysis if no other
616+
// dynamic import is present (https://github.com/vitejs/vite/pull/12732)
617+
export const __hmr_import = (module) => import(/* @vite-ignore */ module);
618+
615619
// For backwards compatibility with @vitejs/plugin-react.
616620
export default { injectIntoGlobalHook };

0 commit comments

Comments
 (0)