Home / Function/ resolveServerOptions() — vite Function Reference

resolveServerOptions() — vite Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  7bbcd1bc_4ca0_af2b_79c0_d079b5e5b839["resolveServerOptions()"]
  a423a1ed_f7d8_0eb5_9b8f_ddfa7fa8147e["index.ts"]
  7bbcd1bc_4ca0_af2b_79c0_d079b5e5b839 -->|defined in| a423a1ed_f7d8_0eb5_9b8f_ddfa7fa8147e
  58c4a210_68fe_1b4d_ed49_d59203f97ef1["resolveConfig()"]
  58c4a210_68fe_1b4d_ed49_d59203f97ef1 -->|calls| 7bbcd1bc_4ca0_af2b_79c0_d079b5e5b839
  50c942bf_5ddd_ac2c_f4f6_571d569b7215["mergeWithDefaults()"]
  7bbcd1bc_4ca0_af2b_79c0_d079b5e5b839 -->|calls| 50c942bf_5ddd_ac2c_f4f6_571d569b7215
  f00607d5_f936_a7c7_9f17_a6349edeac83["searchForWorkspaceRoot()"]
  7bbcd1bc_4ca0_af2b_79c0_d079b5e5b839 -->|calls| f00607d5_f936_a7c7_9f17_a6349edeac83
  abbcb31f_2732_cc49_32a8_c121af61546c["searchForPackageRoot()"]
  7bbcd1bc_4ca0_af2b_79c0_d079b5e5b839 -->|calls| abbcb31f_2732_cc49_32a8_c121af61546c
  97348c69_2196_cc41_4d53_ea075a711af6["resolvedAllowDir()"]
  7bbcd1bc_4ca0_af2b_79c0_d079b5e5b839 -->|calls| 97348c69_2196_cc41_4d53_ea075a711af6
  d9d49dad_960b_4712_7c44_9345473c62e5["isParentDirectory()"]
  7bbcd1bc_4ca0_af2b_79c0_d079b5e5b839 -->|calls| d9d49dad_960b_4712_7c44_9345473c62e5
  3cf1d94a_16a2_96d6_7d1d_9757e22a2557["warn()"]
  7bbcd1bc_4ca0_af2b_79c0_d079b5e5b839 -->|calls| 3cf1d94a_16a2_96d6_7d1d_9757e22a2557
  style 7bbcd1bc_4ca0_af2b_79c0_d079b5e5b839 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/vite/src/node/server/index.ts lines 1145–1227

export function resolveServerOptions(
  root: string,
  raw: ServerOptions | undefined,
  logger: Logger,
): ResolvedServerOptions {
  const _server = mergeWithDefaults(
    {
      ..._serverConfigDefaults,
      host: undefined, // do not set here to detect whether host is set or not
      sourcemapIgnoreList: isInNodeModules,
    },
    raw ?? {},
  )

  const server: ResolvedServerOptions = {
    ..._server,
    fs: {
      ..._server.fs,
      // run searchForWorkspaceRoot only if needed
      allow: raw?.fs?.allow ?? [searchForWorkspaceRoot(root)],
    },
    sourcemapIgnoreList:
      _server.sourcemapIgnoreList === false
        ? () => false
        : _server.sourcemapIgnoreList,
  }

  let allowDirs = server.fs.allow

  if (process.versions.pnp) {
    // running a command fails if cwd doesn't exist and root may not exist
    // search for package root to find a path that exists
    const cwd = searchForPackageRoot(root)
    try {
      const enableGlobalCache =
        execSync('yarn config get enableGlobalCache', { cwd })
          .toString()
          .trim() === 'true'
      const yarnCacheDir = execSync(
        `yarn config get ${enableGlobalCache ? 'globalFolder' : 'cacheFolder'}`,
        { cwd },
      )
        .toString()
        .trim()
      allowDirs.push(yarnCacheDir)
    } catch (e) {
      logger.warn(`Get yarn cache dir error: ${e.message}`, {
        timestamp: true,
      })
    }
  }

  allowDirs = allowDirs.map((i) => resolvedAllowDir(root, i))

  // only push client dir when vite itself is outside-of-root
  const resolvedClientDir = resolvedAllowDir(root, CLIENT_DIR)
  if (!allowDirs.some((dir) => isParentDirectory(dir, resolvedClientDir))) {
    allowDirs.push(resolvedClientDir)
  }

  server.fs.allow = allowDirs

  if (server.origin?.endsWith('/')) {
    server.origin = server.origin.slice(0, -1)
    logger.warn(
      colors.yellow(
        `${colors.bold('(!)')} server.origin should not end with "/". Using "${
          server.origin
        }" instead.`,
      ),
    )
  }

  if (
    process.env.__VITE_ADDITIONAL_SERVER_ALLOWED_HOSTS &&
    Array.isArray(server.allowedHosts)
  ) {
    const additionalHost = process.env.__VITE_ADDITIONAL_SERVER_ALLOWED_HOSTS
    server.allowedHosts = [...server.allowedHosts, additionalHost]
  }

Domain

Subdomains

Called By

Frequently Asked Questions

What does resolveServerOptions() do?
resolveServerOptions() is a function in the vite codebase, defined in packages/vite/src/node/server/index.ts.
Where is resolveServerOptions() defined?
resolveServerOptions() is defined in packages/vite/src/node/server/index.ts at line 1145.
What does resolveServerOptions() call?
resolveServerOptions() calls 6 function(s): isParentDirectory, mergeWithDefaults, resolvedAllowDir, searchForPackageRoot, searchForWorkspaceRoot, warn.
What calls resolveServerOptions()?
resolveServerOptions() is called by 1 function(s): resolveConfig.

Analyze Your Own Codebase

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

Try Supermodel Free