Skip to content

Commit

Permalink
fix(legacy): add guard to modern polyfill chunk (#13719)
Browse files Browse the repository at this point in the history
  • Loading branch information
lsdsjy committed Sep 20, 2023
1 parent 21a62da commit 945dc4d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/plugin-legacy/src/index.ts
Expand Up @@ -237,7 +237,7 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] {
`[@vitejs/plugin-legacy] modern polyfills:`,
modernPolyfills,
)
await buildPolyfillChunk(
const polyfillChunk = await buildPolyfillChunk(
config.mode,
modernPolyfills,
bundle,
Expand All @@ -247,6 +247,9 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] {
opts,
true,
)
if (genLegacy && polyfillChunk) {
polyfillChunk.code = modernChunkLegacyGuard + polyfillChunk.code
}
return
}

Expand Down Expand Up @@ -734,6 +737,8 @@ async function buildPolyfillChunk(

// add the chunk to the bundle
bundle[polyfillChunk.fileName] = polyfillChunk

return polyfillChunk
}

const polyfillId = '\0vite/legacy-polyfills'
Expand Down

0 comments on commit 945dc4d

Please sign in to comment.