Skip to content

Commit

Permalink
fix: Avoid importing in source that __vitePreload has declared (close #…
Browse files Browse the repository at this point in the history
…4016) (#4041)

Co-authored-by: patak <matias.capeletto@gmail.com>
  • Loading branch information
xingxiuyi and patak-dev committed Jul 1, 2021
1 parent eb2e41b commit bd34203
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/vite/src/node/plugins/importAnalysisBuild.ts
Expand Up @@ -161,7 +161,11 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
}
}

if (needPreloadHelper && !ssr) {
if (
needPreloadHelper &&
!ssr &&
!source.includes(`const ${preloadMethod} =`)
) {
str().prepend(`import { ${preloadMethod} } from "${preloadHelperId}";`)
}

Expand Down

0 comments on commit bd34203

Please sign in to comment.