Home / Function/ createLoadHandler() — vite Function Reference

createLoadHandler() — vite Function Reference

Architecture documentation for the createLoadHandler() function in pluginConverter.ts from the vite codebase.

Entity Profile

Dependency Diagram

graph TD
  428f2e15_3be7_8055_9526_1da80db25615["createLoadHandler()"]
  b8dcab0c_e45e_1664_f34c_62cebf0403f4["pluginConverter.ts"]
  428f2e15_3be7_8055_9526_1da80db25615 -->|defined in| b8dcab0c_e45e_1664_f34c_62cebf0403f4
  9f6f139c_8c3d_b748_997b_26d6d6e67035["convertEsbuildPluginToRolldownPlugin()"]
  9f6f139c_8c3d_b748_997b_26d6d6e67035 -->|calls| 428f2e15_3be7_8055_9526_1da80db25615
  1cebaeb4_7ad4_b30a_cf3d_ce32068ff869["idToPathAndNamespace()"]
  428f2e15_3be7_8055_9526_1da80db25615 -->|calls| 1cebaeb4_7ad4_b30a_cf3d_ce32068ff869
  style 428f2e15_3be7_8055_9526_1da80db25615 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/vite/src/node/optimizer/pluginConverter.ts lines 246–294

function createLoadHandler(
  options: esbuild.OnLoadOptions,
  callback: EsbuildOnLoadCallback,
): LoadHandler {
  const textDecoder = new TextDecoder()
  return async function (id) {
    const [idWithoutNamespace, idNamespace] = idToPathAndNamespace(id)
    if (
      options.namespace !== undefined &&
      options.namespace !== 'file' &&
      options.namespace !== idNamespace
    ) {
      return
    }
    if (options.filter !== undefined && !options.filter.test(id)) {
      return
    }

    const result = await callback.call(this, {
      path: idWithoutNamespace,
      namespace: idNamespace,
      suffix: '',
      pluginData: {},
      with: {},
    })
    if (!result) return
    if (result.errors && result.errors.length > 0) {
      throw new AggregateError(result.errors)
    }
    if (
      (result.warnings && result.warnings.length > 0) ||
      (result.watchDirs && result.watchDirs.length > 0) ||
      result.contents == null
    ) {
      throw new Error('not implemented')
    }
    for (const file of result.watchFiles ?? []) {
      this.addWatchFile(file)
    }

    return {
      code:
        typeof result.contents === 'string'
          ? result.contents
          : textDecoder.decode(result.contents),
      moduleType: result.loader,
    }
  }
}

Subdomains

Frequently Asked Questions

What does createLoadHandler() do?
createLoadHandler() is a function in the vite codebase, defined in packages/vite/src/node/optimizer/pluginConverter.ts.
Where is createLoadHandler() defined?
createLoadHandler() is defined in packages/vite/src/node/optimizer/pluginConverter.ts at line 246.
What does createLoadHandler() call?
createLoadHandler() calls 1 function(s): idToPathAndNamespace.
What calls createLoadHandler()?
createLoadHandler() is called by 1 function(s): convertEsbuildPluginToRolldownPlugin.

Analyze Your Own Codebase

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

Try Supermodel Free