Home / Function/ rolldownScanPlugin() — vite Function Reference

rolldownScanPlugin() — vite Function Reference

Architecture documentation for the rolldownScanPlugin() function in scan.ts from the vite codebase.

Entity Profile

Dependency Diagram

graph TD
  01ea698c_723c_af06_e469_c7d7c469b6bb["rolldownScanPlugin()"]
  6c7a7f5e_5d30_3576_49bf_9041362fd3fd["scan.ts"]
  01ea698c_723c_af06_e469_c7d7c469b6bb -->|defined in| 6c7a7f5e_5d30_3576_49bf_9041362fd3fd
  24024bc8_5434_bc2f_7acb_d02914457eae["prepareRolldownScanner()"]
  24024bc8_5434_bc2f_7acb_d02914457eae -->|calls| 01ea698c_723c_af06_e469_c7d7c469b6bb
  a4adb1a7_cf54_091f_eb63_8217e684a8e1["normalizePath()"]
  01ea698c_723c_af06_e469_c7d7c469b6bb -->|calls| a4adb1a7_cf54_091f_eb63_8217e684a8e1
  a6007673_0baa_9293_6af0_ff74ed056981["transformGlobImport()"]
  01ea698c_723c_af06_e469_c7d7c469b6bb -->|calls| a6007673_0baa_9293_6af0_ff74ed056981
  7df81f3b_6fcf_3c38_e4eb_a447f9d9da7f["extractImportPaths()"]
  01ea698c_723c_af06_e469_c7d7c469b6bb -->|calls| 7df81f3b_6fcf_3c38_e4eb_a447f9d9da7f
  dfa2b928_25a4_a78f_1e11_1e7e643cae09["resolve()"]
  01ea698c_723c_af06_e469_c7d7c469b6bb -->|calls| dfa2b928_25a4_a78f_1e11_1e7e643cae09
  50ac7e51_9f94_e985_bfec_ae95273b23b0["isInNodeModules()"]
  01ea698c_723c_af06_e469_c7d7c469b6bb -->|calls| 50ac7e51_9f94_e985_bfec_ae95273b23b0
  908e9e35_950f_ad37_ffa9_0058622aa7e8["isOptimizable()"]
  01ea698c_723c_af06_e469_c7d7c469b6bb -->|calls| 908e9e35_950f_ad37_ffa9_0058622aa7e8
  67dc5388_0a8f_7b39_e3da_79bf8a3ed488["shouldExternalizeDep()"]
  01ea698c_723c_af06_e469_c7d7c469b6bb -->|calls| 67dc5388_0a8f_7b39_e3da_79bf8a3ed488
  26e0aa25_abdb_a755_dedb_61e78323162d["moduleListContains()"]
  01ea698c_723c_af06_e469_c7d7c469b6bb -->|calls| 26e0aa25_abdb_a755_dedb_61e78323162d
  cb488b23_3da2_8fce_842d_98fe1fe4a384["isScannable()"]
  01ea698c_723c_af06_e469_c7d7c469b6bb -->|calls| cb488b23_3da2_8fce_842d_98fe1fe4a384
  10b9dea8_362c_1af2_93be_afa4dd9aed9e["cleanUrl()"]
  01ea698c_723c_af06_e469_c7d7c469b6bb -->|calls| 10b9dea8_362c_1af2_93be_afa4dd9aed9e
  acb05845_9984_6792_9aae_b58486b613b5["resolveId()"]
  01ea698c_723c_af06_e469_c7d7c469b6bb -->|calls| acb05845_9984_6792_9aae_b58486b613b5
  style 01ea698c_723c_af06_e469_c7d7c469b6bb fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/vite/src/node/optimizer/scan.ts lines 340–717

function rolldownScanPlugin(
  environment: ScanEnvironment,
  depImports: Record<string, string>,
  missing: Record<string, string>,
  entries: string[],
): Plugin[] {
  const seen = new Map<string, string | undefined>()
  async function resolveId(
    id: string,
    importer?: string,
  ): Promise<PartialResolvedId | null> {
    return environment.pluginContainer.resolveId(
      id,
      importer && normalizePath(importer),
      { scan: true },
    )
  }
  const resolve = async (id: string, importer?: string) => {
    const key = id + (importer && path.dirname(importer))
    if (seen.has(key)) {
      return seen.get(key)
    }
    const resolved = await resolveId(id, importer)
    const res = resolved?.id
    seen.set(key, res)
    return res
  }

  const optimizeDepsOptions = environment.config.optimizeDeps
  const include = optimizeDepsOptions.include
  const exclude = [
    ...(optimizeDepsOptions.exclude ?? []),
    '@vite/client',
    '@vite/env',
  ]

  const externalUnlessEntry = ({ path }: { path: string }) => ({
    id: path,
    external: !entries.includes(path),
  })

  const doTransformGlobImport = async (
    contents: string,
    id: string,
    loader: Loader,
  ) => {
    let transpiledContents: string
    // transpile because `transformGlobImport` only expects js
    if (loader !== 'js') {
      const result = transformSync(id, contents, { lang: loader })
      if (result.errors.length > 0) {
        throw new AggregateError(result.errors, 'oxc transform error')
      }
      transpiledContents = result.code
    } else {
      transpiledContents = contents
    }

    const result = await transformGlobImport(
      transpiledContents,
      id,
      environment.config.root,
      resolve,
    )

    return result?.s.toString() || transpiledContents
  }

  const scripts: Record<
    string,
    {
      contents: string
      loader: Loader
    }
  > = {}

  const htmlTypeOnLoadCallback = async (id: string): Promise<string> => {
    let raw = await fsp.readFile(id, 'utf-8')
    // Avoid matching the content of the comment
    raw = raw.replace(commentRE, '<!---->')
    const isHtml = id.endsWith('.html')

Subdomains

Frequently Asked Questions

What does rolldownScanPlugin() do?
rolldownScanPlugin() is a function in the vite codebase, defined in packages/vite/src/node/optimizer/scan.ts.
Where is rolldownScanPlugin() defined?
rolldownScanPlugin() is defined in packages/vite/src/node/optimizer/scan.ts at line 340.
What does rolldownScanPlugin() call?
rolldownScanPlugin() calls 11 function(s): cleanUrl, extractImportPaths, isInNodeModules, isOptimizable, isScannable, moduleListContains, normalizePath, resolve, and 3 more.
What calls rolldownScanPlugin()?
rolldownScanPlugin() is called by 1 function(s): prepareRolldownScanner.

Analyze Your Own Codebase

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

Try Supermodel Free