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

Function buildPolyfillChunk

packages/plugin-legacy/src/index.ts:873–969  ·  view source on GitHub ↗
(
  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,
)

Source from the content-addressed store, hash-verified

871}
872
873async function buildPolyfillChunk(
874 ctx: Rollup.PluginContext,
875 mode: string,
876 imports: Set<string>,
877 bundle: Rollup.OutputBundle,
878 facadeToChunkMap: Map<string, string>,
879 buildOptions: BuildOptions,
880 format: 'iife' | 'es',
881 rollupOutputOptions: Rollup.NormalizedOutputOptions,
882 excludeSystemJS?: boolean,
883 prependModenChunkLegacyGuard?: boolean,
884) {
885 let { minify, assetsDir, sourcemap } = buildOptions
886 minify = minify ? 'terser' : false
887 const res = await build({
888 mode,
889 // so that everything is resolved from here
890 root: path.dirname(fileURLToPath(import.meta.url)),
891 configFile: false,
892 logLevel: 'error',
893 plugins: [
894 polyfillsPlugin(imports, excludeSystemJS),
895 prependModenChunkLegacyGuard && prependModenChunkLegacyGuardPlugin(),
896 ],
897 build: {
898 write: false,
899 minify,
900 assetsDir,
901 sourcemap,
902 rolldownOptions: {
903 input: {
904 polyfills: polyfillId,
905 },
906 output: {
907 format,
908 hashCharacters: rollupOutputOptions.hashCharacters,
909 entryFileNames: rollupOutputOptions.entryFileNames,
910 sourcemapBaseUrl: rollupOutputOptions.sourcemapBaseUrl,
911 },
912 },
913 },
914 // Don't run esbuild for transpilation or minification
915 // because we don't want to transpile code.
916 esbuild: false,
917 optimizeDeps: {
918 esbuildOptions: {
919 // If a value above 'es5' is set, esbuild injects helper functions which uses es2015 features.
920 // This limits the input code not to include es2015+ codes.
921 // But core-js is the only dependency which includes commonjs code
922 // and core-js doesn't include es2015+ codes.
923 target: 'es5',
924 },
925 },
926 })
927 const _polyfillChunk = Array.isArray(res) ? res[0] : res
928 if (!('output' in _polyfillChunk)) return
929 const polyfillChunk = _polyfillChunk.output.find(
930 (chunk) => chunk.type === 'chunk' && chunk.isEntry,

Callers 1

generateBundleFunction · 0.85

Calls 5

buildFunction · 0.90
polyfillsPluginFunction · 0.85
emitFileMethod · 0.80
setMethod · 0.45

Tested by

no test coverage detected