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(css): unknown file error happened with lightningcss #16306

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {
createSerialPromiseQueue,
emptyCssComments,
encodeURIPath,
escapeReplaceValue,
generateCodeFrame,
getHash,
getPackageManagerCommand,
Expand Down Expand Up @@ -2754,12 +2755,12 @@ async function compileLightningCSS(
switch (dep.type) {
case 'url':
if (skipUrlReplacer(dep.url)) {
css = css.replace(dep.placeholder, dep.url)
css = css.replace(dep.placeholder, escapeReplaceValue(dep.url))
sapphi-red marked this conversation as resolved.
Show resolved Hide resolved
break
}
deps.add(dep.url)
if (urlReplacer) {
css = css.replace(dep.placeholder, await urlReplacer(dep.url, id))
css = css.replace(dep.placeholder, escapeReplaceValue(await urlReplacer(dep.url, id)))
}
break
default:
Expand Down
4 changes: 4 additions & 0 deletions packages/vite/src/node/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1321,6 +1321,10 @@ export function escapeRegex(str: string): string {
return str.replace(escapeRegexRE, '\\$&')
}

export function escapeReplaceValue(str: string): string {
return str.replaceAll('$', '$$$$' /* this is escaped $$ */)
}

type CommandType = 'install' | 'uninstall' | 'update'
export function getPackageManagerCommand(
type: CommandType = 'install',
Expand Down