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
  8fd1d7ae_4758_a029_20c6_a5380f519c70["urlToRequire()"]
  c7f42e34_1c62_9250_3035_ae380c3322e2["utils.ts"]
  8fd1d7ae_4758_a029_20c6_a5380f519c70 -->|defined in| c7f42e34_1c62_9250_3035_ae380c3322e2
  7afd8a83_3fc2_6187_5517_fcf280baab01["rewrite()"]
  7afd8a83_3fc2_6187_5517_fcf280baab01 -->|calls| 8fd1d7ae_4758_a029_20c6_a5380f519c70
  7517df93_2b97_cb05_d1cf_00c25c305369["transform()"]
  7517df93_2b97_cb05_d1cf_00c25c305369 -->|calls| 8fd1d7ae_4758_a029_20c6_a5380f519c70
  6250716c_21b1_0cc1_e1e2_7a6422314a1c["isExternalUrl()"]
  8fd1d7ae_4758_a029_20c6_a5380f519c70 -->|calls| 6250716c_21b1_0cc1_e1e2_7a6422314a1c
  a8062318_f6bb_a517_1db7_944a69436439["isDataUrl()"]
  8fd1d7ae_4758_a029_20c6_a5380f519c70 -->|calls| a8062318_f6bb_a517_1db7_944a69436439
  4cf6f751_9c34_b14d_fc83_8e42ececf2b6["parseUriParts()"]
  8fd1d7ae_4758_a029_20c6_a5380f519c70 -->|calls| 4cf6f751_9c34_b14d_fc83_8e42ececf2b6
  style 8fd1d7ae_4758_a029_20c6_a5380f519c70 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, defined in packages/compiler-sfc/src/templateCompilerModules/utils.ts.
Where is urlToRequire() defined?
urlToRequire() is defined in packages/compiler-sfc/src/templateCompilerModules/utils.ts at line 5.
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