Skip to content

Commit

Permalink
fix(legacy): add guard to modern polyfill chunk
Browse files Browse the repository at this point in the history
  • Loading branch information
lsdsjy committed Jul 27, 2023
1 parent 24c12fe commit 9776253
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/plugin-legacy/src/index.ts
Original file line number Diff line number Diff line change
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 (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 9776253

Please sign in to comment.