Home / Function/ mergeWithDefaultsRecursively() — vite Function Reference

mergeWithDefaultsRecursively() — vite Function Reference

Architecture documentation for the mergeWithDefaultsRecursively() function in utils.ts from the vite codebase.

Entity Profile

Dependency Diagram

graph TD
  69defeb8_ff5a_8fd6_86b9_943d5033a081["mergeWithDefaultsRecursively()"]
  031bc221_67a8_c579_f2bf_bb30a08beeb2["utils.ts"]
  69defeb8_ff5a_8fd6_86b9_943d5033a081 -->|defined in| 031bc221_67a8_c579_f2bf_bb30a08beeb2
  50c942bf_5ddd_ac2c_f4f6_571d569b7215["mergeWithDefaults()"]
  50c942bf_5ddd_ac2c_f4f6_571d569b7215 -->|calls| 69defeb8_ff5a_8fd6_86b9_943d5033a081
  319b98aa_6cdb_37ba_7e51_e737640bf2fa["value()"]
  69defeb8_ff5a_8fd6_86b9_943d5033a081 -->|calls| 319b98aa_6cdb_37ba_7e51_e737640bf2fa
  2aff86e8_0c9d_22cb_6536_c1321e1aaa1d["isObject()"]
  69defeb8_ff5a_8fd6_86b9_943d5033a081 -->|calls| 2aff86e8_0c9d_22cb_6536_c1321e1aaa1d
  style 69defeb8_ff5a_8fd6_86b9_943d5033a081 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/vite/src/node/utils.ts lines 1197–1222

function mergeWithDefaultsRecursively<
  D extends Record<string, any>,
  V extends Record<string, any>,
>(defaults: D, values: V): MergeWithDefaultsResult<D, V> {
  const merged: Record<string, any> = defaults
  for (const key in values) {
    const value = values[key]
    // let null to set the value (e.g. `server.watch: null`)
    if (value === undefined) continue

    const existing = merged[key]
    if (existing === undefined) {
      merged[key] = value
      continue
    }

    if (isObject(existing) && isObject(value)) {
      merged[key] = mergeWithDefaultsRecursively(existing, value)
      continue
    }

    // use replace even for arrays
    merged[key] = value
  }
  return merged as MergeWithDefaultsResult<D, V>
}

Domain

Subdomains

Frequently Asked Questions

What does mergeWithDefaultsRecursively() do?
mergeWithDefaultsRecursively() is a function in the vite codebase, defined in packages/vite/src/node/utils.ts.
Where is mergeWithDefaultsRecursively() defined?
mergeWithDefaultsRecursively() is defined in packages/vite/src/node/utils.ts at line 1197.
What does mergeWithDefaultsRecursively() call?
mergeWithDefaultsRecursively() calls 2 function(s): isObject, value.
What calls mergeWithDefaultsRecursively()?
mergeWithDefaultsRecursively() is called by 1 function(s): mergeWithDefaults.

Analyze Your Own Codebase

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

Try Supermodel Free