Home / Function/ loadConfig() — vite Function Reference

loadConfig() — vite Function Reference

Architecture documentation for the loadConfig() function in vitestSetup.ts from the vite codebase.

Entity Profile

Dependency Diagram

graph TD
  9c39db4a_5ddd_67a5_69e8_01c342e795f3["loadConfig()"]
  804dc5f9_3eef_472e_8575_1233b4358f17["vitestSetup.ts"]
  9c39db4a_5ddd_67a5_69e8_01c342e795f3 -->|defined in| 804dc5f9_3eef_472e_8575_1233b4358f17
  434087ce_6cf5_5cbc_f3dc_7499162ee37b["startDefaultServe()"]
  434087ce_6cf5_5cbc_f3dc_7499162ee37b -->|calls| 9c39db4a_5ddd_67a5_69e8_01c342e795f3
  8ac737b0_3331_a657_5931_95cb4a02d224["createInMemoryLogger()"]
  9c39db4a_5ddd_67a5_69e8_01c342e795f3 -->|calls| 8ac737b0_3331_a657_5931_95cb4a02d224
  2f02250e_c9b5_1182_af18_cdb92e1a2740["throwHtmlParseError()"]
  9c39db4a_5ddd_67a5_69e8_01c342e795f3 -->|calls| 2f02250e_c9b5_1182_af18_cdb92e1a2740
  style 9c39db4a_5ddd_67a5_69e8_01c342e795f3 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

playground/vitestSetup.ts lines 226–274

async function loadConfig(configEnv: ConfigEnv) {
  let config: UserConfig | null = null

  // config file named by convention as the *.spec.ts folder
  const variantName = path.basename(path.dirname(testPath))
  if (variantName !== '__tests__') {
    const configVariantPath = path.resolve(
      rootDir,
      `vite.config-${variantName}.js`,
    )
    if (fs.existsSync(configVariantPath)) {
      const res = await loadConfigFromFile(configEnv, configVariantPath)
      if (res) {
        config = res.config
      }
    }
  }
  // config file from test root dir
  if (!config) {
    const res = await loadConfigFromFile(configEnv, undefined, rootDir)
    if (res) {
      config = res.config
    }
  }

  const options: InlineConfig = {
    root: rootDir,
    logLevel: 'silent',
    configFile: false,
    server: {
      watch: {
        // During tests we edit the files too fast and sometimes chokidar
        // misses change events, so enforce polling for consistency
        usePolling: true,
        interval: 100,
      },
    },
    build: {
      // esbuild do not minify ES lib output since that would remove pure annotations and break tree-shaking
      // skip transpilation during tests to make it faster
      target: 'esnext',
      // tests are flaky when `emptyOutDir` is `true`
      emptyOutDir: false,
    },
    customLogger: createInMemoryLogger(serverLogs),
    plugins: [throwHtmlParseError()],
  }
  return mergeConfig(options, config || {})
}

Domain

Subdomains

Frequently Asked Questions

What does loadConfig() do?
loadConfig() is a function in the vite codebase, defined in playground/vitestSetup.ts.
Where is loadConfig() defined?
loadConfig() is defined in playground/vitestSetup.ts at line 226.
What does loadConfig() call?
loadConfig() calls 2 function(s): createInMemoryLogger, throwHtmlParseError.
What calls loadConfig()?
loadConfig() is called by 1 function(s): startDefaultServe.

Analyze Your Own Codebase

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

Try Supermodel Free