Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(build): decode urls in CSS files (fix #15109) #15246

Merged
merged 5 commits into from
Dec 12, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,22 +264,23 @@ export function cssPlugin(config: ResolvedConfig): Plugin {
const ssr = options?.ssr === true

const urlReplacer: CssUrlReplacer = async (url, importer) => {
if (checkPublicFile(url, config)) {
const decodedUrl = decodeURI(url)
if (checkPublicFile(decodedUrl, config)) {
if (encodePublicUrlsInCSS(config)) {
return publicFileToBuiltUrl(url, config)
return publicFileToBuiltUrl(decodedUrl, config)
} else {
return joinUrlSegments(config.base, url)
return joinUrlSegments(config.base, decodedUrl)
}
}
const resolved = await resolveUrl(url, importer)
const resolved = await resolveUrl(decodedUrl, importer)
if (resolved) {
return fileToUrl(resolved, config, this)
}
if (config.command === 'build') {
const isExternal = config.build.rollupOptions.external
? resolveUserExternal(
config.build.rollupOptions.external,
url, // use URL as id since id could not be resolved
decodedUrl, // use URL as id since id could not be resolved
id,
false,
)
Expand All @@ -288,11 +289,11 @@ export function cssPlugin(config: ResolvedConfig): Plugin {
if (!isExternal) {
// #9800 If we cannot resolve the css url, leave a warning.
config.logger.warnOnce(
`\n${url} referenced in ${id} didn't resolve at build time, it will remain unchanged to be resolved at runtime`,
`\n${decodedUrl} referenced in ${id} didn't resolve at build time, it will remain unchanged to be resolved at runtime`,
)
}
}
return url
return decodedUrl
}

const {
Expand Down