Home / Function/ urlToRequire() — vue Function Reference

urlToRequire() — vue Function Reference

Architecture documentation for the urlToRequire() function in utils.ts from the vue codebase.

Entity Profile

Dependency Diagram

graph TD
  924fad0f_bcf5_3302_0184_f5a0b88ea288["urlToRequire()"]
  d7162635_9fea_6331_1bc2_0da7f96c79b8["rewrite()"]
  d7162635_9fea_6331_1bc2_0da7f96c79b8 -->|calls| 924fad0f_bcf5_3302_0184_f5a0b88ea288
  c1b3f083_bc44_5037_61ae_e8e7ce19b488["transform()"]
  c1b3f083_bc44_5037_61ae_e8e7ce19b488 -->|calls| 924fad0f_bcf5_3302_0184_f5a0b88ea288
  295c8fea_1a3a_244f_148c_bfcb3a5a2f4b["isExternalUrl()"]
  924fad0f_bcf5_3302_0184_f5a0b88ea288 -->|calls| 295c8fea_1a3a_244f_148c_bfcb3a5a2f4b
  96cdf151_5244_c56f_4a17_7fc393cf1155["isDataUrl()"]
  924fad0f_bcf5_3302_0184_f5a0b88ea288 -->|calls| 96cdf151_5244_c56f_4a17_7fc393cf1155
  4bc13eab_721c_1277_2f90_945594c2d7c5["parseUriParts()"]
  924fad0f_bcf5_3302_0184_f5a0b88ea288 -->|calls| 4bc13eab_721c_1277_2f90_945594c2d7c5
  style 924fad0f_bcf5_3302_0184_f5a0b88ea288 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/compiler-sfc/src/templateCompilerModules/utils.ts lines 5–58

export function urlToRequire(
  url: string,
  transformAssetUrlsOption: TransformAssetUrlsOptions = {}
): string {
  const returnValue = `"${url}"`
  // same logic as in transform-require.js
  const firstChar = url.charAt(0)
  if (firstChar === '~') {
    const secondChar = url.charAt(1)
    url = url.slice(secondChar === '/' ? 2 : 1)
  }

  if (isExternalUrl(url) || isDataUrl(url) || firstChar === '#') {
    return returnValue
  }

  const uriParts = parseUriParts(url)
  if (transformAssetUrlsOption.base) {
    // explicit base - directly rewrite the url into absolute url
    // does not apply to absolute urls or urls that start with `@`
    // since they are aliases
    if (firstChar === '.' || firstChar === '~') {
      // Allow for full hostnames provided in options.base
      const base = parseUriParts(transformAssetUrlsOption.base)
      const protocol = base.protocol || ''
      const host = base.host ? protocol + '//' + base.host : ''
      const basePath = base.path || '/'
      // when packaged in the browser, path will be using the posix-
      // only version provided by rollup-plugin-node-builtins.
      return `"${host}${(path.posix || path).join(
        basePath,
        uriParts.path + (uriParts.hash || '')
      )}"`
    }
  }

  if (
    transformAssetUrlsOption.includeAbsolute ||
    firstChar === '.' ||
    firstChar === '~' ||
    firstChar === '@'
  ) {
    if (!uriParts.hash) {
      return `require("${url}")`
    } else {
      // support uri fragment case by excluding it from
      // the require and instead appending it as string;
      // assuming that the path part is sufficient according to
      // the above caseing(t.i. no protocol-auth-host parts expected)
      return `require("${uriParts.path}") + "${uriParts.hash}"`
    }
  }
  return returnValue
}

Domain

Subdomains

Frequently Asked Questions

What does urlToRequire() do?
urlToRequire() is a function in the vue codebase.
What does urlToRequire() call?
urlToRequire() calls 3 function(s): isDataUrl, isExternalUrl, parseUriParts.
What calls urlToRequire()?
urlToRequire() is called by 2 function(s): rewrite, transform.

Analyze Your Own Codebase

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

Try Supermodel Free