Home / Function/ buildPolyfillChunk() — vite Function Reference

buildPolyfillChunk() — vite Function Reference

Architecture documentation for the buildPolyfillChunk() function in index.ts from the vite codebase.

Entity Profile

Dependency Diagram

graph TD
  49d850e2_8fd6_07a7_8f83_58cf64932a71["buildPolyfillChunk()"]
  9776ecb6_00c0_b3b9_b3f7_177fedabeacc["index.ts"]
  49d850e2_8fd6_07a7_8f83_58cf64932a71 -->|defined in| 9776ecb6_00c0_b3b9_b3f7_177fedabeacc
  cf21e8d8_cce6_30a7_7732_696ed5cdf103["viteLegacyPlugin()"]
  cf21e8d8_cce6_30a7_7732_696ed5cdf103 -->|calls| 49d850e2_8fd6_07a7_8f83_58cf64932a71
  fa252842_abf0_8950_e740_d3a45e902d99["polyfillsPlugin()"]
  49d850e2_8fd6_07a7_8f83_58cf64932a71 -->|calls| fa252842_abf0_8950_e740_d3a45e902d99
  a7649197_476f_f6d6_789f_bc82f5fd3ea4["prependModenChunkLegacyGuardPlugin()"]
  49d850e2_8fd6_07a7_8f83_58cf64932a71 -->|calls| a7649197_476f_f6d6_789f_bc82f5fd3ea4
  style 49d850e2_8fd6_07a7_8f83_58cf64932a71 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/plugin-legacy/src/index.ts lines 834–930

async function buildPolyfillChunk(
  ctx: Rollup.PluginContext,
  mode: string,
  imports: Set<string>,
  bundle: Rollup.OutputBundle,
  facadeToChunkMap: Map<string, string>,
  buildOptions: BuildOptions,
  format: 'iife' | 'es',
  rollupOutputOptions: Rollup.NormalizedOutputOptions,
  excludeSystemJS?: boolean,
  prependModenChunkLegacyGuard?: boolean,
) {
  let { minify, assetsDir, sourcemap } = buildOptions
  minify = minify ? 'terser' : false
  const res = await build({
    mode,
    // so that everything is resolved from here
    root: path.dirname(fileURLToPath(import.meta.url)),
    configFile: false,
    logLevel: 'error',
    plugins: [
      polyfillsPlugin(imports, excludeSystemJS),
      prependModenChunkLegacyGuard && prependModenChunkLegacyGuardPlugin(),
    ],
    build: {
      write: false,
      minify,
      assetsDir,
      sourcemap,
      rollupOptions: {
        input: {
          polyfills: polyfillId,
        },
        output: {
          format,
          hashCharacters: rollupOutputOptions.hashCharacters,
          entryFileNames: rollupOutputOptions.entryFileNames,
          sourcemapBaseUrl: rollupOutputOptions.sourcemapBaseUrl,
        },
      },
    },
    // Don't run esbuild for transpilation or minification
    // because we don't want to transpile code.
    esbuild: false,
    optimizeDeps: {
      esbuildOptions: {
        // If a value above 'es5' is set, esbuild injects helper functions which uses es2015 features.
        // This limits the input code not to include es2015+ codes.
        // But core-js is the only dependency which includes commonjs code
        // and core-js doesn't include es2015+ codes.
        target: 'es5',
      },
    },
  })
  const _polyfillChunk = Array.isArray(res) ? res[0] : res
  if (!('output' in _polyfillChunk)) return
  const polyfillChunk = _polyfillChunk.output.find(
    (chunk) => chunk.type === 'chunk' && chunk.isEntry,
  ) as Rollup.OutputChunk

  // associate the polyfill chunk to every entry chunk so that we can retrieve
  // the polyfill filename in index html transform
  for (const key in bundle) {
    const chunk = bundle[key]
    if (chunk.type === 'chunk' && chunk.facadeModuleId) {
      facadeToChunkMap.set(chunk.facadeModuleId, polyfillChunk.fileName)
    }
  }

  // add the chunk to the bundle
  ctx.emitFile({
    type: 'prebuilt-chunk',
    name: polyfillChunk.name,
    fileName: polyfillChunk.fileName,
    code: polyfillChunk.code,
    facadeModuleId: polyfillChunk.facadeModuleId ?? undefined,
    isEntry: polyfillChunk.isEntry,
    isDynamicEntry: polyfillChunk.isDynamicEntry,
    exports: [],
    map: polyfillChunk.map ?? undefined,
    sourcemapFileName: polyfillChunk.sourcemapFileName ?? undefined,

Domain

Subdomains

Called By

Frequently Asked Questions

What does buildPolyfillChunk() do?
buildPolyfillChunk() is a function in the vite codebase, defined in packages/plugin-legacy/src/index.ts.
Where is buildPolyfillChunk() defined?
buildPolyfillChunk() is defined in packages/plugin-legacy/src/index.ts at line 834.
What does buildPolyfillChunk() call?
buildPolyfillChunk() calls 2 function(s): polyfillsPlugin, prependModenChunkLegacyGuardPlugin.
What calls buildPolyfillChunk()?
buildPolyfillChunk() is called by 1 function(s): viteLegacyPlugin.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free