Home / Function/ getSortedPluginsByHook() — vite Function Reference

getSortedPluginsByHook() — vite Function Reference

Architecture documentation for the getSortedPluginsByHook() function in index.ts from the vite codebase.

Entity Profile

Dependency Diagram

graph TD
  a188e507_b323_f6f4_af53_0ba33b92284c["getSortedPluginsByHook()"]
  3bf7f0de_2a9f_6f04_cead_0321b3b7af01["index.ts"]
  a188e507_b323_f6f4_af53_0ba33b92284c -->|defined in| 3bf7f0de_2a9f_6f04_cead_0321b3b7af01
  5db25367_d823_be14_869d_fc9affb91c51["runConfigHook()"]
  5db25367_d823_be14_869d_fc9affb91c51 -->|calls| a188e507_b323_f6f4_af53_0ba33b92284c
  dfd74513_1566_83d7_5d5e_d003f8a4d096["runConfigEnvironmentHook()"]
  dfd74513_1566_83d7_5d5e_d003f8a4d096 -->|calls| a188e507_b323_f6f4_af53_0ba33b92284c
  8e5f0af2_5386_8a8f_0cb4_1863cc4b1cdf["createPluginHookUtils()"]
  8e5f0af2_5386_8a8f_0cb4_1863cc4b1cdf -->|calls| a188e507_b323_f6f4_af53_0ba33b92284c
  style a188e507_b323_f6f4_af53_0ba33b92284c fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/vite/src/node/plugins/index.ts lines 159–187

export function getSortedPluginsByHook<K extends keyof Plugin>(
  hookName: K,
  plugins: readonly Plugin[],
): PluginWithRequiredHook<K>[] {
  const sortedPlugins: Plugin[] = []
  // Use indexes to track and insert the ordered plugins directly in the
  // resulting array to avoid creating 3 extra temporary arrays per hook
  let pre = 0,
    normal = 0,
    post = 0
  for (const plugin of plugins) {
    const hook = plugin[hookName]
    if (hook) {
      if (typeof hook === 'object') {
        if (hook.order === 'pre') {
          sortedPlugins.splice(pre++, 0, plugin)
          continue
        }
        if (hook.order === 'post') {
          sortedPlugins.splice(pre + normal + post++, 0, plugin)
          continue
        }
      }
      sortedPlugins.splice(pre + normal++, 0, plugin)
    }
  }

  return sortedPlugins as PluginWithRequiredHook<K>[]
}

Domain

Subdomains

Frequently Asked Questions

What does getSortedPluginsByHook() do?
getSortedPluginsByHook() is a function in the vite codebase, defined in packages/vite/src/node/plugins/index.ts.
Where is getSortedPluginsByHook() defined?
getSortedPluginsByHook() is defined in packages/vite/src/node/plugins/index.ts at line 159.
What calls getSortedPluginsByHook()?
getSortedPluginsByHook() is called by 3 function(s): createPluginHookUtils, runConfigEnvironmentHook, runConfigHook.

Analyze Your Own Codebase

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

Try Supermodel Free