Home / Function/ checkPublicFile() — vite Function Reference

checkPublicFile() — vite Function Reference

Architecture documentation for the checkPublicFile() function in publicDir.ts from the vite codebase.

Function typescript ViteCore ConfigEngine calls 5 called by 11

Entity Profile

Dependency Diagram

graph TD
  be351481_35b7_f392_a229_ac14e1fa7efb["checkPublicFile()"]
  c6b6e85a_866b_a3e1_08e0_f9aa4550a2d3["publicDir.ts"]
  be351481_35b7_f392_a229_ac14e1fa7efb -->|defined in| c6b6e85a_866b_a3e1_08e0_f9aa4550a2d3
  2b04bf20_6455_3250_24f8_b60c71116be3["assetPlugin()"]
  2b04bf20_6455_3250_24f8_b60c71116be3 -->|calls| be351481_35b7_f392_a229_ac14e1fa7efb
  eec82f76_7029_ae97_4449_1665a4f204d8["fileToDevUrl()"]
  eec82f76_7029_ae97_4449_1665a4f204d8 -->|calls| be351481_35b7_f392_a229_ac14e1fa7efb
  86195de2_9c12_1f7e_7a3e_0754a5695ebe["fileToBuiltUrl()"]
  86195de2_9c12_1f7e_7a3e_0754a5695ebe -->|calls| be351481_35b7_f392_a229_ac14e1fa7efb
  70054416_c841_dc8b_5bd9_4793198b4325["urlToBuiltUrl()"]
  70054416_c841_dc8b_5bd9_4793198b4325 -->|calls| be351481_35b7_f392_a229_ac14e1fa7efb
  157cb972_609e_022e_1ec5_3ed6f7e4f45c["cssPlugin()"]
  157cb972_609e_022e_1ec5_3ed6f7e4f45c -->|calls| be351481_35b7_f392_a229_ac14e1fa7efb
  6aa50cd4_4412_2a02_b76b_495614715811["compilePostCSS()"]
  6aa50cd4_4412_2a02_b76b_495614715811 -->|calls| be351481_35b7_f392_a229_ac14e1fa7efb
  cc40a51d_2143_be43_f128_4841bfa5e9d3["compileLightningCSS()"]
  cc40a51d_2143_be43_f128_4841bfa5e9d3 -->|calls| be351481_35b7_f392_a229_ac14e1fa7efb
  39f26be8_b1d9_a756_3043_474687a6bbb7["buildHtmlPlugin()"]
  39f26be8_b1d9_a756_3043_474687a6bbb7 -->|calls| be351481_35b7_f392_a229_ac14e1fa7efb
  a1fc1de5_905b_efe7_d960_3597604fbdfe["importAnalysisPlugin()"]
  a1fc1de5_905b_efe7_d960_3597604fbdfe -->|calls| be351481_35b7_f392_a229_ac14e1fa7efb
  bdd49406_d977_da9f_c847_bc5405877a0d["shouldPreTransform()"]
  bdd49406_d977_da9f_c847_bc5405877a0d -->|calls| be351481_35b7_f392_a229_ac14e1fa7efb
  bdac5327_5085_933f_41df_0fc270134a38["loadAndTransform()"]
  bdac5327_5085_933f_41df_0fc270134a38 -->|calls| be351481_35b7_f392_a229_ac14e1fa7efb
  10b9dea8_362c_1af2_93be_afa4dd9aed9e["cleanUrl()"]
  be351481_35b7_f392_a229_ac14e1fa7efb -->|calls| 10b9dea8_362c_1af2_93be_afa4dd9aed9e
  e47eece7_ff23_8be2_4d16_908b40321824["getPublicFiles()"]
  be351481_35b7_f392_a229_ac14e1fa7efb -->|calls| e47eece7_ff23_8be2_4d16_908b40321824
  style be351481_35b7_f392_a229_ac14e1fa7efb fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/vite/src/node/publicDir.ts lines 36–64

export function checkPublicFile(
  url: string,
  config: ResolvedConfig,
): string | undefined {
  // note if the file is in /public, the resolver would have returned it
  // as-is so it's not going to be a fully resolved path.
  const { publicDir } = config
  if (!publicDir || url[0] !== '/') {
    return
  }

  const fileName = cleanUrl(url)

  // short-circuit if we have an in-memory publicFiles cache
  const publicFiles = getPublicFiles(config)
  if (publicFiles) {
    return publicFiles.has(fileName)
      ? normalizePath(path.join(publicDir, fileName))
      : undefined
  }

  const publicFile = normalizePath(path.join(publicDir, fileName))
  if (!publicFile.startsWith(withTrailingSlash(publicDir))) {
    // can happen if URL starts with '../'
    return
  }

  return tryStatSync(publicFile)?.isFile() ? publicFile : undefined
}

Domain

Subdomains

Frequently Asked Questions

What does checkPublicFile() do?
checkPublicFile() is a function in the vite codebase, defined in packages/vite/src/node/publicDir.ts.
Where is checkPublicFile() defined?
checkPublicFile() is defined in packages/vite/src/node/publicDir.ts at line 36.
What does checkPublicFile() call?
checkPublicFile() calls 5 function(s): cleanUrl, getPublicFiles, normalizePath, tryStatSync, withTrailingSlash.
What calls checkPublicFile()?
checkPublicFile() is called by 11 function(s): assetPlugin, buildHtmlPlugin, compileLightningCSS, compilePostCSS, cssPlugin, fileToBuiltUrl, fileToDevUrl, importAnalysisPlugin, and 3 more.

Analyze Your Own Codebase

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

Try Supermodel Free