doUrlReplace() — vite Function Reference
Architecture documentation for the doUrlReplace() function in css.ts from the vite codebase.
Entity Profile
Dependency Diagram
graph TD 4274dcf6_df8f_0a7e_51d3_aa97fd2b2204["doUrlReplace()"] c3eb47df_971b_0616_6c9f_29b3ded72224["css.ts"] 4274dcf6_df8f_0a7e_51d3_aa97fd2b2204 -->|defined in| c3eb47df_971b_0616_6c9f_29b3ded72224 195cd9c3_f2f4_e90a_85a2_ca6bf6eb0b86["rewriteCssUrls()"] 195cd9c3_f2f4_e90a_85a2_ca6bf6eb0b86 -->|calls| 4274dcf6_df8f_0a7e_51d3_aa97fd2b2204 a73b802f_5d97_3b91_585d_ee35e8c8e6d4["rewriteCssDataUris()"] a73b802f_5d97_3b91_585d_ee35e8c8e6d4 -->|calls| 4274dcf6_df8f_0a7e_51d3_aa97fd2b2204 adbeefd5_f002_aded_c354_d39e64e7c473["rewriteCssImageSet()"] adbeefd5_f002_aded_c354_d39e64e7c473 -->|calls| 4274dcf6_df8f_0a7e_51d3_aa97fd2b2204 bafacb32_492f_c34a_cdad_d01b78d6a2b3["skipUrlReplacer()"] 4274dcf6_df8f_0a7e_51d3_aa97fd2b2204 -->|calls| bafacb32_492f_c34a_cdad_d01b78d6a2b3 style 4274dcf6_df8f_0a7e_51d3_aa97fd2b2204 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/vite/src/node/plugins/css.ts lines 2131–2170
async function doUrlReplace(
rawUrl: string,
matched: string,
replacer: CssUrlReplacer,
funcName: string = 'url',
) {
let wrap = ''
const first = rawUrl[0]
let unquotedUrl = rawUrl
if (first === `"` || first === `'`) {
wrap = first
unquotedUrl = rawUrl.slice(1, -1)
}
if (skipUrlReplacer(unquotedUrl)) {
return matched
}
// Remove escape sequences to get the actual file name before resolving.
unquotedUrl = unquotedUrl.replace(/\\(\W)/g, '$1')
let newUrl = await replacer(unquotedUrl, rawUrl)
if (newUrl === false) {
return matched
}
// The new url might need wrapping even if the original did not have it, e.g.
// if a space was added during replacement or the URL contains ")"
if (wrap === '' && (newUrl !== encodeURI(newUrl) || newUrl.includes(')'))) {
wrap = '"'
}
// If wrapping in single quotes and newUrl also contains single quotes, switch to double quotes.
// Give preference to double quotes since SVG inlining converts double quotes to single quotes.
if (wrap === "'" && newUrl.includes("'")) {
wrap = '"'
}
// Escape double quotes if they exist (they also tend to be rarer than single quotes)
if (wrap === '"' && newUrl.includes('"')) {
newUrl = newUrl.replace(nonEscapedDoubleQuoteRe, '\\"')
}
return `${funcName}(${wrap}${newUrl}${wrap})`
}
Domain
Subdomains
Defined In
Calls
Source
Frequently Asked Questions
What does doUrlReplace() do?
doUrlReplace() is a function in the vite codebase, defined in packages/vite/src/node/plugins/css.ts.
Where is doUrlReplace() defined?
doUrlReplace() is defined in packages/vite/src/node/plugins/css.ts at line 2131.
What does doUrlReplace() call?
doUrlReplace() calls 1 function(s): skipUrlReplacer.
What calls doUrlReplace()?
doUrlReplace() is called by 3 function(s): rewriteCssDataUris, rewriteCssImageSet, rewriteCssUrls.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free