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

Function renderChunk

packages/vite/src/node/plugins/worker.ts:571–628  ·  view source on GitHub ↗
(code, chunk, outputOptions)

Source from the content-addressed store, hash-verified

569 ...(isBuild
570 ? {
571 renderChunk(code, chunk, outputOptions) {
572 let s: MagicString
573 const result = () => {
574 return (
575 s && {
576 code: s.toString(),
577 map: this.environment.config.build.sourcemap
578 ? s.generateMap({ hires: 'boundary' })
579 : null,
580 }
581 )
582 }
583 workerAssetUrlRE.lastIndex = 0
584 if (workerAssetUrlRE.test(code)) {
585 const toRelativeRuntime =
586 createToImportMetaURLBasedRelativeRuntime(
587 outputOptions.format,
588 this.environment.config.isWorker,
589 )
590
591 let match: RegExpExecArray | null
592 s = new MagicString(code)
593 workerAssetUrlRE.lastIndex = 0
594
595 // Replace "__VITE_WORKER_ASSET__5aa0ddc0__" using relative paths
596 const workerOutputCache = workerOutputCaches.get(
597 config.mainConfig || config,
598 )!
599
600 while ((match = workerAssetUrlRE.exec(code))) {
601 const [full, hash] = match
602 const filename =
603 workerOutputCache.getEntryFilenameFromHash(hash)
604 if (!filename) {
605 this.warn(`Could not find worker asset for hash: ${hash}`)
606 continue
607 }
608 const replacement = toOutputFilePathInJS(
609 this.environment,
610 filename,
611 'asset',
612 chunk.fileName,
613 'js',
614 toRelativeRuntime,
615 )
616 const replacementString =
617 typeof replacement === 'string'
618 ? JSON.stringify(encodeURIPath(replacement)).slice(1, -1)
619 : `"+${replacement.runtime}+"`
620 s.update(
621 match.index,
622 match.index + full.length,
623 replacementString,
624 )
625 }
626 }
627 return result()
628 },

Callers

nothing calls this directly

Calls 7

toOutputFilePathInJSFunction · 0.90
encodeURIPathFunction · 0.90
resultFunction · 0.85
warnMethod · 0.65
getMethod · 0.45

Tested by

no test coverage detected