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

Function injectEsbuildHelpers

packages/vite/src/node/plugins/esbuild.ts:368–386  ·  view source on GitHub ↗
(
  esbuildCode: string,
  format: string,
)

Source from the content-addressed store, hash-verified

366// We don't need to create a MagicString here because both the helpers and
367// the headers don't modify the sourcemap
368export const injectEsbuildHelpers = (
369 esbuildCode: string,
370 format: string,
371): string => {
372 const contentIndex =
373 format === 'iife'
374 ? Math.max(esbuildCode.search(IIFE_BEGIN_RE), 0)
375 : format === 'umd'
376 ? esbuildCode.indexOf(`(function(`) // same for minified or not
377 : 0
378
379 if (contentIndex > 0) {
380 const esbuildHelpers = esbuildCode.slice(0, contentIndex)
381 return esbuildCode
382 .slice(contentIndex)
383 .replace('"use strict";', (m: string) => m + esbuildHelpers)
384 }
385 return esbuildCode
386}
387
388export const buildEsbuildPlugin = (): Plugin => {
389 return {

Callers 2

esbuild.spec.tsFile · 0.90
renderChunkFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected