Home / Class/ DevEnvironment Class — vite Architecture

DevEnvironment Class — vite Architecture

Architecture documentation for the DevEnvironment class in environment.ts from the vite codebase.

Entity Profile

Dependency Diagram

graph TD
  f634223d_ed8e_a65b_08f8_a839ec17994a["DevEnvironment"]
  7916c84f_5621_2b3b_d220_a171ebce997f["environment.ts"]
  f634223d_ed8e_a65b_08f8_a839ec17994a -->|defined in| 7916c84f_5621_2b3b_d220_a171ebce997f
  85e1964a_55f8_22ab_02ed_c666202e1669["pluginContainer()"]
  f634223d_ed8e_a65b_08f8_a839ec17994a -->|method| 85e1964a_55f8_22ab_02ed_c666202e1669
  6ea66dc7_258c_4d4e_457c_a36e57776e88["constructor()"]
  f634223d_ed8e_a65b_08f8_a839ec17994a -->|method| 6ea66dc7_258c_4d4e_457c_a36e57776e88
  5d79d65d_2f96_8145_d09b_a6354feab599["init()"]
  f634223d_ed8e_a65b_08f8_a839ec17994a -->|method| 5d79d65d_2f96_8145_d09b_a6354feab599
  0edbbec3_6066_80b2_5f47_367d86a7705f["listen()"]
  f634223d_ed8e_a65b_08f8_a839ec17994a -->|method| 0edbbec3_6066_80b2_5f47_367d86a7705f
  be964a75_40a0_c608_ed3a_1a730415cb0f["fetchModule()"]
  f634223d_ed8e_a65b_08f8_a839ec17994a -->|method| be964a75_40a0_c608_ed3a_1a730415cb0f
  ae322642_9768_b13d_7947_305b43316fa0["reloadModule()"]
  f634223d_ed8e_a65b_08f8_a839ec17994a -->|method| ae322642_9768_b13d_7947_305b43316fa0
  c99812b1_1fd5_5046_98fa_678c5c80c0fb["transformRequest()"]
  f634223d_ed8e_a65b_08f8_a839ec17994a -->|method| c99812b1_1fd5_5046_98fa_678c5c80c0fb
  a7a71598_1136_b87a_07e7_f81a84ec9ab6["warmupRequest()"]
  f634223d_ed8e_a65b_08f8_a839ec17994a -->|method| a7a71598_1136_b87a_07e7_f81a84ec9ab6
  dd164f22_a6d3_7e8d_43c3_45e219e70176["invalidateModule()"]
  f634223d_ed8e_a65b_08f8_a839ec17994a -->|method| dd164f22_a6d3_7e8d_43c3_45e219e70176
  2a568e89_e3e7_9284_fd00_e1a9ca1ec09a["close()"]
  f634223d_ed8e_a65b_08f8_a839ec17994a -->|method| 2a568e89_e3e7_9284_fd00_e1a9ca1ec09a
  b6ef989d_5a20_eb85_097b_a92459d6c1e0["waitForRequestsIdle()"]
  f634223d_ed8e_a65b_08f8_a839ec17994a -->|method| b6ef989d_5a20_eb85_097b_a92459d6c1e0
  be640272_c343_f5ae_1cf1_91d595faa5f8["_registerRequestProcessing()"]
  f634223d_ed8e_a65b_08f8_a839ec17994a -->|method| be640272_c343_f5ae_1cf1_91d595faa5f8

Relationship Graph

Source Code

packages/vite/src/node/server/environment.ts lines 55–332

export class DevEnvironment extends BaseEnvironment {
  mode = 'dev' as const
  moduleGraph: EnvironmentModuleGraph

  depsOptimizer?: DepsOptimizer
  /**
   * @internal
   */
  _remoteRunnerOptions: DevEnvironmentContext['remoteRunner']

  get pluginContainer(): EnvironmentPluginContainer<DevEnvironment> {
    if (!this._pluginContainer)
      throw new Error(
        `${this.name} environment.pluginContainer called before initialized`,
      )
    return this._pluginContainer
  }
  /**
   * @internal
   */
  _pluginContainer: EnvironmentPluginContainer<DevEnvironment> | undefined

  /**
   * @internal
   */
  _closing: boolean = false
  /**
   * @internal
   */
  _pendingRequests: Map<
    string,
    {
      request: Promise<TransformResult | null>
      timestamp: number
      abort: () => void
    }
  >
  /**
   * @internal
   */
  _crawlEndFinder: CrawlEndFinder

  /**
   * Hot channel for this environment. If not provided or disabled,
   * it will be a noop channel that does nothing.
   *
   * @example
   * environment.hot.send({ type: 'full-reload' })
   */
  hot: NormalizedHotChannel
  constructor(
    name: string,
    config: ResolvedConfig,
    context: DevEnvironmentContext,
  ) {
    let options = config.environments[name]
    if (!options) {
      throw new Error(`Environment "${name}" is not defined in the config.`)
    }
    if (context.options) {
      options = mergeConfig(
        options,
        context.options,
      ) as ResolvedEnvironmentOptions
    }
    super(name, config, options)

    this._pendingRequests = new Map()

    this.moduleGraph = new EnvironmentModuleGraph(name, (url: string) =>
      this.pluginContainer!.resolveId(url, undefined),
    )

    this._crawlEndFinder = setupOnCrawlEnd()

    this._remoteRunnerOptions = context.remoteRunner ?? {}

    this.hot = context.transport
      ? isWebSocketServer in context.transport
        ? context.transport
        : normalizeHotChannel(context.transport, context.hot)

Domain

Frequently Asked Questions

What is the DevEnvironment class?
DevEnvironment is a class in the vite codebase, defined in packages/vite/src/node/server/environment.ts.
Where is DevEnvironment defined?
DevEnvironment is defined in packages/vite/src/node/server/environment.ts at line 55.

Analyze Your Own Codebase

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

Try Supermodel Free