Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(legacy): add guard to modern polyfill chunk #13719

Merged
merged 2 commits into from
Sep 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 (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
Loading