Home / Type/ Plugin Type — vite Architecture

Plugin Type — vite Architecture

Architecture documentation for the Plugin type/interface in plugin.ts from the vite codebase.

Entity Profile

Dependency Diagram

graph TD
  1dc2cf7d_5d97_c778_8c33_6449a7607aef["Plugin"]
  5abb8c87_ffcb_f2d4_7421_e36705d9e5c7["plugin.ts"]
  1dc2cf7d_5d97_c778_8c33_6449a7607aef -->|defined in| 5abb8c87_ffcb_f2d4_7421_e36705d9e5c7
  style 1dc2cf7d_5d97_c778_8c33_6449a7607aef fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/vite/src/node/plugin.ts lines 101–371

export interface Plugin<A = any> extends RolldownPlugin<A> {
  /**
   * Perform custom handling of HMR updates.
   * The handler receives an options containing changed filename, timestamp, a
   * list of modules affected by the file change, and the dev server instance.
   *
   * - The hook can return a filtered list of modules to narrow down the update.
   *   e.g. for a Vue SFC, we can narrow down the part to update by comparing
   *   the descriptors.
   *
   * - The hook can also return an empty array and then perform custom updates
   *   by sending a custom hmr payload via environment.hot.send().
   *
   * - If the hook doesn't return a value, the hmr update will be performed as
   *   normal.
   */
  hotUpdate?: ObjectHook<
    (
      this: MinimalPluginContext & { environment: DevEnvironment },
      options: HotUpdateOptions,
    ) =>
      | Array<EnvironmentModuleNode>
      | void
      | Promise<Array<EnvironmentModuleNode> | void>
  >

  /**
   * extend hooks with ssr flag
   */
  resolveId?: ObjectHook<
    (
      this: PluginContext,
      source: string,
      importer: string | undefined,
      options: {
        kind?: ImportKind
        custom?: CustomPluginOptions
        ssr?: boolean | undefined
        /**
         * @internal
         */
        scan?: boolean | undefined
        isEntry: boolean
      },
    ) => Promise<ResolveIdResult> | ResolveIdResult,
    { filter?: { id?: StringFilter<RegExp> } }
  >
  load?: ObjectHook<
    (
      this: PluginContext,
      id: string,
      options?: {
        ssr?: boolean | undefined
      },
    ) => Promise<LoadResult> | LoadResult,
    { filter?: { id?: StringFilter } }
  >
  transform?: ObjectHook<
    (
      this: TransformPluginContext,
      code: string,
      id: string,
      options?: {
        moduleType: ModuleType
        ssr?: boolean | undefined
      },
    ) => Promise<TransformResult> | TransformResult,
    {
      filter?: {
        id?: StringFilter
        code?: StringFilter
        moduleType?: ModuleTypeFilter
      }
    }
  >
  /**
   * Opt-in this plugin into the shared plugins pipeline.
   * For backward-compatibility, plugins are re-recreated for each environment
   * during `vite build --app`
   * We have an opt-in per plugin, and a general `builder.sharedPlugins`
   * In a future major, we'll flip the default to be shared by default

Frequently Asked Questions

What is the Plugin type?
Plugin is a type/interface in the vite codebase, defined in packages/vite/src/node/plugin.ts.
Where is Plugin defined?
Plugin is defined in packages/vite/src/node/plugin.ts at line 101.

Analyze Your Own Codebase

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

Try Supermodel Free