Home / Function/ listen() — vite Function Reference

listen() — vite Function Reference

Architecture documentation for the listen() function in fullBundleEnvironment.ts from the vite codebase.

Entity Profile

Dependency Diagram

graph TD
  848ddbbd_3d45_b055_e84a_874b4ca3fd45["listen()"]
  8fcd8920_61ef_93b8_499a_c18a48b852e5["FullBundleDevEnvironment"]
  848ddbbd_3d45_b055_e84a_874b4ca3fd45 -->|defined in| 8fcd8920_61ef_93b8_499a_c18a48b852e5
  e6c19722_5c65_17df_83d9_4bb453d26d5b["getRolldownOptions()"]
  848ddbbd_3d45_b055_e84a_874b4ca3fd45 -->|calls| e6c19722_5c65_17df_83d9_4bb453d26d5b
  2ccc36f4_103c_b60e_efaa_01ea14db6138["handleHmrOutput()"]
  848ddbbd_3d45_b055_e84a_874b4ca3fd45 -->|calls| 2ccc36f4_103c_b60e_efaa_01ea14db6138
  9d14b302_f3e1_c6ad_ee27_ab91f346722a["waitForInitialBuildFinish()"]
  848ddbbd_3d45_b055_e84a_874b4ca3fd45 -->|calls| 9d14b302_f3e1_c6ad_ee27_ab91f346722a
  0edbbec3_6066_80b2_5f47_367d86a7705f["listen()"]
  848ddbbd_3d45_b055_e84a_874b4ca3fd45 -->|calls| 0edbbec3_6066_80b2_5f47_367d86a7705f
  20693f43_58cf_ecea_9bd8_cc1c093c10f5["setupIfNeeded()"]
  848ddbbd_3d45_b055_e84a_874b4ca3fd45 -->|calls| 20693f43_58cf_ecea_9bd8_cc1c093c10f5
  66f69099_a55f_0956_bd23_5711ae0c0f21["getAll()"]
  848ddbbd_3d45_b055_e84a_874b4ca3fd45 -->|calls| 66f69099_a55f_0956_bd23_5711ae0c0f21
  350125bb_754e_f5e3_28c9_3c404a3e4edb["prepareError()"]
  848ddbbd_3d45_b055_e84a_874b4ca3fd45 -->|calls| 350125bb_754e_f5e3_28c9_3c404a3e4edb
  f5ce538f_7fa5_1e64_6120_5970da060f0d["clear()"]
  848ddbbd_3d45_b055_e84a_874b4ca3fd45 -->|calls| f5ce538f_7fa5_1e64_6120_5970da060f0d
  2e1469ca_9e59_dcc2_bdc7_05126c765fd0["error()"]
  848ddbbd_3d45_b055_e84a_874b4ca3fd45 -->|calls| 2e1469ca_9e59_dcc2_bdc7_05126c765fd0
  76e38b65_cb19_7bed_a56c_352d99366e3b["set()"]
  848ddbbd_3d45_b055_e84a_874b4ca3fd45 -->|calls| 76e38b65_cb19_7bed_a56c_352d99366e3b
  4e748f4a_42c0_e310_88f6_d950ac923c8d["get()"]
  848ddbbd_3d45_b055_e84a_874b4ca3fd45 -->|calls| 4e748f4a_42c0_e310_88f6_d950ac923c8d
  style 848ddbbd_3d45_b055_e84a_874b4ca3fd45 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/vite/src/node/server/environments/fullBundleEnvironment.ts lines 90–188

  override async listen(_server: ViteDevServer): Promise<void> {
    this.hot.listen()

    debug?.('INITIAL: setup bundle options')
    const rollupOptions = await this.getRolldownOptions()
    // NOTE: only single outputOptions is supported here
    if (
      Array.isArray(rollupOptions.output) &&
      rollupOptions.output.length > 1
    ) {
      throw new Error('multiple output options are not supported in dev mode')
    }
    const outputOptions = (
      Array.isArray(rollupOptions.output)
        ? rollupOptions.output[0]
        : rollupOptions.output
    )!

    this.hot.on('vite:module-loaded', (payload, client) => {
      const clientId = this.clients.setupIfNeeded(client)
      this.devEngine.registerModules(clientId, payload.modules)
    })
    this.hot.on('vite:client:disconnect', (_payload, client) => {
      const clientId = this.clients.delete(client)
      if (clientId) {
        this.devEngine.removeClient(clientId)
      }
    })

    this.devEngine = await dev(rollupOptions, outputOptions, {
      onHmrUpdates: (result) => {
        if (result instanceof Error) {
          // TODO: send to the specific client
          for (const client of this.clients.getAll()) {
            client.send({
              type: 'error',
              err: prepareError(result),
            })
          }
          return
        }
        const { updates, changedFiles } = result
        if (changedFiles.length === 0) {
          return
        }
        if (updates.every((update) => update.update.type === 'Noop')) {
          debug?.(`ignored file change for ${changedFiles.join(', ')}`)
          return
        }
        for (const { clientId, update } of updates) {
          const client = this.clients.get(clientId)
          if (client) {
            this.invalidateCalledModules.get(client)?.clear()
            this.handleHmrOutput(client, changedFiles, update)
          }
        }
      },
      onOutput: (result) => {
        if (result instanceof Error) {
          this.logger.error(colors.red(`✘ Build error: ${result.message}`), {
            error: result,
          })
          this.hot.send({
            type: 'error',
            err: prepareError(result),
          })
          return
        }

        // NOTE: don't clear memoryFiles here as incremental build re-uses the files
        for (const outputFile of result.output) {
          this.memoryFiles.set(outputFile.fileName, () => {
            const source =
              outputFile.type === 'chunk' ? outputFile.code : outputFile.source
            return {
              source,
              etag: getEtag(Buffer.from(source), { weak: true }),
            }
          })
        }
      },

Domain

Subdomains

Frequently Asked Questions

What does listen() do?
listen() is a function in the vite codebase, defined in packages/vite/src/node/server/environments/fullBundleEnvironment.ts.
Where is listen() defined?
listen() is defined in packages/vite/src/node/server/environments/fullBundleEnvironment.ts at line 90.
What does listen() call?
listen() calls 11 function(s): clear, error, get, getAll, getRolldownOptions, handleHmrOutput, listen, prepareError, and 3 more.

Analyze Your Own Codebase

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

Try Supermodel Free