Skip to content

Commit

Permalink
perf: wrap dynamic import to skip analysis of dynamic imports (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBarre committed Apr 5, 2023
1 parent 14767fc commit 4371853
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ ${result.code}
window.$RefreshReg$ = prevRefreshReg;
window.$RefreshSig$ = prevRefreshSig;
import(/* @vite-ignore */ import.meta.url).then((currentExports) => {
RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
RefreshRuntime.registerExportsForReactRefresh("${id}", currentExports);
import.meta.hot.accept((nextExports) => {
if (!nextExports) return;
Expand Down
4 changes: 4 additions & 0 deletions src/refresh-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,5 +612,9 @@ function predicateOnExport(moduleExports, predicate) {
return true;
}

// Hides vite-ignored dynamic import so that Vite can skip analysis if no other
// dynamic import is present (https://github.com/vitejs/vite/pull/12732)
export const __hmr_import = (module) => import(/* @vite-ignore */ module);

// For backwards compatibility with @vitejs/plugin-react.
export default { injectIntoGlobalHook };

0 comments on commit 4371853

Please sign in to comment.