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

Function generateBundle

packages/vite/src/node/plugins/asset.ts:265–312  ·  view source on GitHub ↗
(_, bundle)

Source from the content-addressed store, hash-verified

263 : {}),
264
265 generateBundle(_, bundle) {
266 // Remove empty entry point file
267 let importedFiles: Set<string> | undefined
268 for (const file in bundle) {
269 const chunk = bundle[file]
270 if (
271 chunk.type === 'chunk' &&
272 chunk.isEntry &&
273 chunk.moduleIds.length === 1 &&
274 config.assetsInclude(chunk.moduleIds[0]) &&
275 this.getModuleInfo(chunk.moduleIds[0])?.meta['vite:asset']
276 ) {
277 if (!importedFiles) {
278 importedFiles = new Set()
279 for (const file in bundle) {
280 const chunk = bundle[file]
281 if (chunk.type === 'chunk') {
282 for (const importedFile of chunk.imports) {
283 importedFiles.add(importedFile)
284 }
285 for (const importedFile of chunk.dynamicImports) {
286 importedFiles.add(importedFile)
287 }
288 }
289 }
290 }
291 if (!importedFiles.has(file)) {
292 delete bundle[file]
293 }
294 }
295 }
296
297 // do not emit assets for SSR build
298 if (
299 config.command === 'build' &&
300 !this.environment.config.build.emitAssets
301 ) {
302 for (const file in bundle) {
303 if (
304 bundle[file].type === 'asset' &&
305 !file.endsWith('ssr-manifest.json') &&
306 !jsSourceMapRE.test(file)
307 ) {
308 delete bundle[file]
309 }
310 }
311 }
312 },
313
314 watchChange(id) {
315 assetCache.get(this.environment)?.delete(normalizePath(id))

Callers

nothing calls this directly

Calls 3

addMethod · 0.80
hasMethod · 0.80
getModuleInfoMethod · 0.45

Tested by

no test coverage detected