Home / Class/ ChunkMetadataMap Class — vite Architecture

ChunkMetadataMap Class — vite Architecture

Architecture documentation for the ChunkMetadataMap class in build.ts from the vite codebase.

Entity Profile

Dependency Diagram

graph TD
  5f248dff_9bc5_81c9_2fb1_99ac1026a9ef["ChunkMetadataMap"]
  45981d85_cbdd_e969_8c88_c17072ea0eda["build.ts"]
  5f248dff_9bc5_81c9_2fb1_99ac1026a9ef -->|defined in| 45981d85_cbdd_e969_8c88_c17072ea0eda
  fbdae1fb_a173_808c_93fb_3d0375d90515["_getKey()"]
  5f248dff_9bc5_81c9_2fb1_99ac1026a9ef -->|method| fbdae1fb_a173_808c_93fb_3d0375d90515
  b530eca3_f288_ee9d_6640_7a355c8bbb90["_getDefaultValue()"]
  5f248dff_9bc5_81c9_2fb1_99ac1026a9ef -->|method| b530eca3_f288_ee9d_6640_7a355c8bbb90
  51afdf58_3045_64b1_cf5b_929b1091e877["get()"]
  5f248dff_9bc5_81c9_2fb1_99ac1026a9ef -->|method| 51afdf58_3045_64b1_cf5b_929b1091e877
  2d80d05c_e180_bb95_94ab_4eb9d9abe3e2["reset()"]
  5f248dff_9bc5_81c9_2fb1_99ac1026a9ef -->|method| 2d80d05c_e180_bb95_94ab_4eb9d9abe3e2
  e2e6edbb_7f9c_497a_7e44_feef63f1b53f["clearResetChunks()"]
  5f248dff_9bc5_81c9_2fb1_99ac1026a9ef -->|method| e2e6edbb_7f9c_497a_7e44_feef63f1b53f

Relationship Graph

Source Code

packages/vite/src/node/build.ts lines 1186–1235

export class ChunkMetadataMap {
  private _inner = new Map<string, ChunkMetadata | AssetMetadata>()
  private _resetChunks = new Set<string>()

  private _getKey(chunk: RenderedChunk | OutputChunk | OutputAsset): string {
    return 'preliminaryFileName' in chunk
      ? chunk.preliminaryFileName
      : chunk.fileName
  }

  private _getDefaultValue(
    chunk: RenderedChunk | OutputChunk | OutputAsset,
  ): ChunkMetadata | AssetMetadata {
    return chunk.type === 'chunk'
      ? {
          importedAssets: new Set(),
          importedCss: new Set(),
          // NOTE: adding this as a workaround for now ideally we'd want to remove this workaround
          // use shared `chunk.modules` object to allow mutation on js side plugins
          __modules: chunk.modules,
        }
      : {
          importedAssets: new Set(),
          importedCss: new Set(),
        }
  }

  get(
    chunk: RenderedChunk | OutputChunk | OutputAsset,
  ): ChunkMetadata | AssetMetadata {
    const key = this._getKey(chunk)
    if (!this._inner.has(key)) {
      this._inner.set(key, this._getDefaultValue(chunk))
    }
    return this._inner.get(key)!
  }

  // reset chunk metadata on the first RenderChunk call for watch mode
  reset(chunk: RenderedChunk | OutputChunk | OutputAsset): void {
    const key = this._getKey(chunk)
    if (this._resetChunks.has(key)) return

    this._resetChunks.add(key)
    this._inner.set(key, this._getDefaultValue(chunk))
  }

  clearResetChunks(): void {
    this._resetChunks.clear()
  }
}

Domain

Frequently Asked Questions

What is the ChunkMetadataMap class?
ChunkMetadataMap is a class in the vite codebase, defined in packages/vite/src/node/build.ts.
Where is ChunkMetadataMap defined?
ChunkMetadataMap is defined in packages/vite/src/node/build.ts at line 1186.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free