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

Function buildEsbuildPlugin

packages/vite/src/node/plugins/esbuild.ts:388–425  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

386}
387
388export const buildEsbuildPlugin = (): Plugin => {
389 return {
390 name: 'vite:esbuild-transpile',
391 applyToEnvironment(environment) {
392 return environment.config.esbuild !== false
393 },
394 async renderChunk(code, chunk, opts) {
395 // avoid on legacy chunks since it produces legacy-unsafe code
396 // e.g. rewriting object properties into shorthands
397 if (this.environment.config.isOutputOptionsForLegacyChunks?.(opts)) {
398 return null
399 }
400
401 const config = this.environment.config
402 const options = resolveEsbuildTranspileOptions(config, opts.format)
403
404 if (!options) {
405 return null
406 }
407
408 const res = await transformWithEsbuild(
409 code,
410 chunk.fileName,
411 options,
412 undefined,
413 config,
414 undefined,
415 true,
416 )
417
418 if (config.build.lib) {
419 res.code = injectEsbuildHelpers(res.code, opts.format)
420 }
421
422 return res
423 },
424 }
425}
426
427export function resolveEsbuildTranspileOptions(
428 config: ResolvedConfig,

Callers 1

resolveBuildPluginsFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected