Home / Function/ wrapEnvironmentHook() — vite Function Reference

wrapEnvironmentHook() — vite Function Reference

Architecture documentation for the wrapEnvironmentHook() function in build.ts from the vite codebase.

Entity Profile

Dependency Diagram

graph TD
  1c197603_e2cb_3034_de04_9a0dcc54dcdc["wrapEnvironmentHook()"]
  45981d85_cbdd_e969_8c88_c17072ea0eda["build.ts"]
  1c197603_e2cb_3034_de04_9a0dcc54dcdc -->|defined in| 45981d85_cbdd_e969_8c88_c17072ea0eda
  d7a9e9fe_edc0_c70e_690b_4591b789faca["injectEnvironmentToHooks()"]
  d7a9e9fe_edc0_c70e_690b_4591b789faca -->|calls| 1c197603_e2cb_3034_de04_9a0dcc54dcdc
  58719e23_70bd_67e0_1ed8_f61c19ec725b["getHookHandler()"]
  1c197603_e2cb_3034_de04_9a0dcc54dcdc -->|calls| 58719e23_70bd_67e0_1ed8_f61c19ec725b
  cc503659_fea6_f7a4_0eca_f9b89ae2eb3a["injectChunkMetadata()"]
  1c197603_e2cb_3034_de04_9a0dcc54dcdc -->|calls| cc503659_fea6_f7a4_0eca_f9b89ae2eb3a
  7d3ee640_04e8_d5d3_6065_cf5e3e14e4b7["injectEnvironmentInContext()"]
  1c197603_e2cb_3034_de04_9a0dcc54dcdc -->|calls| 7d3ee640_04e8_d5d3_6065_cf5e3e14e4b7
  b2845655_f75f_18a4_fb50_94d0f40983fe["wrapHookObject()"]
  1c197603_e2cb_3034_de04_9a0dcc54dcdc -->|calls| b2845655_f75f_18a4_fb50_94d0f40983fe
  style 1c197603_e2cb_3034_de04_9a0dcc54dcdc fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/vite/src/node/build.ts lines 1402–1438

function wrapEnvironmentHook<HookName extends keyof Plugin>(
  environment: Environment,
  chunkMetadataMap: ChunkMetadataMap,
  plugin: Plugin,
  hookName: HookName,
): Plugin[HookName] {
  const hook = plugin[hookName]
  if (!hook) return

  const fn = getHookHandler(hook)
  if (typeof fn !== 'function') return hook

  const handler: Plugin[HookName] = function (
    this: PluginContext,
    ...args: any[]
  ) {
    if (hookName === 'renderChunk') {
      injectChunkMetadata(chunkMetadataMap, args[1], true)
    }
    if (hookName === 'augmentChunkHash') {
      injectChunkMetadata(chunkMetadataMap, args[0])
    }
    if (hookName === 'generateBundle' || hookName === 'writeBundle') {
      const bundle = args[1] as OutputBundle
      for (const chunk of Object.values(bundle)) {
        injectChunkMetadata(chunkMetadataMap, chunk)
      }
    }
    return fn.call(injectEnvironmentInContext(this, environment), ...args)
  }

  if ('handler' in hook) {
    return wrapHookObject(hook, handler)
  } else {
    return handler
  }
}

Domain

Subdomains

Frequently Asked Questions

What does wrapEnvironmentHook() do?
wrapEnvironmentHook() is a function in the vite codebase, defined in packages/vite/src/node/build.ts.
Where is wrapEnvironmentHook() defined?
wrapEnvironmentHook() is defined in packages/vite/src/node/build.ts at line 1402.
What does wrapEnvironmentHook() call?
wrapEnvironmentHook() calls 4 function(s): getHookHandler, injectChunkMetadata, injectEnvironmentInContext, wrapHookObject.
What calls wrapEnvironmentHook()?
wrapEnvironmentHook() is called by 1 function(s): injectEnvironmentToHooks.

Analyze Your Own Codebase

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

Try Supermodel Free