Skip to content

Commit 945dc4d

Browse files
authored
fix(legacy): add guard to modern polyfill chunk (#13719)
1 parent 21a62da commit 945dc4d

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

packages/plugin-legacy/src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] {
237237
`[@vitejs/plugin-legacy] modern polyfills:`,
238238
modernPolyfills,
239239
)
240-
await buildPolyfillChunk(
240+
const polyfillChunk = await buildPolyfillChunk(
241241
config.mode,
242242
modernPolyfills,
243243
bundle,
@@ -247,6 +247,9 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] {
247247
opts,
248248
true,
249249
)
250+
if (genLegacy && polyfillChunk) {
251+
polyfillChunk.code = modernChunkLegacyGuard + polyfillChunk.code
252+
}
250253
return
251254
}
252255

@@ -734,6 +737,8 @@ async function buildPolyfillChunk(
734737

735738
// add the chunk to the bundle
736739
bundle[polyfillChunk.fileName] = polyfillChunk
740+
741+
return polyfillChunk
737742
}
738743

739744
const polyfillId = '\0vite/legacy-polyfills'

0 commit comments

Comments
 (0)