MCPcopy
hub / github.com/vitejs/vite / generateBundle

Function generateBundle

packages/plugin-legacy/src/index.ts:296–381  ·  view source on GitHub ↗
(opts, bundle)

Source from the content-addressed store, hash-verified

294 apply: 'build',
295
296 async generateBundle(opts, bundle) {
297 if (config.build.ssr) {
298 return
299 }
300
301 const chunkFileNameToPolyfills =
302 outputToChunkFileNameToPolyfills.get(opts)
303 if (chunkFileNameToPolyfills == null) {
304 throw new Error(
305 'Internal @vitejs/plugin-legacy error: discovered polyfills should exist',
306 )
307 }
308
309 if (!isLegacyBundle(bundle)) {
310 // Merge discovered modern polyfills to `modernPolyfills`
311 for (const { modern } of chunkFileNameToPolyfills.values()) {
312 modern.forEach((p) => modernPolyfills.add(p))
313 }
314 if (!modernPolyfills.size) {
315 return
316 }
317 if (isDebug) {
318 console.log(
319 `[@vitejs/plugin-legacy] modern polyfills:`,
320 modernPolyfills,
321 )
322 }
323 await buildPolyfillChunk(
324 this,
325 config.mode,
326 modernPolyfills,
327 bundle,
328 facadeToModernPolyfillMap,
329 config.build,
330 'es',
331 opts,
332 true,
333 genLegacy,
334 )
335 return
336 }
337
338 if (!genLegacy) {
339 return
340 }
341
342 // Merge discovered legacy polyfills to `legacyPolyfills`
343 for (const { legacy } of chunkFileNameToPolyfills.values()) {
344 legacy.forEach((p) => legacyPolyfills.add(p))
345 }
346
347 // legacy bundle
348 if (options.polyfills !== false) {
349 // check if the target needs Promise polyfill because SystemJS relies on it
350 // https://github.com/systemjs/systemjs#ie11-support
351 await detectPolyfills(
352 `Promise.resolve(); Promise.all();`,
353 targets,

Callers

nothing calls this directly

Calls 7

isLegacyBundleFunction · 0.85
buildPolyfillChunkFunction · 0.85
detectPolyfillsFunction · 0.85
addMethod · 0.80
logMethod · 0.80
getImportMapFilenameFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected