fix(vite): ignore query/hash when resolving public assets (#27306)

This commit is contained in:
Daniel Roe 2024-05-22 15:40:29 +01:00 committed by GitHub
parent eb0bebc46d
commit 305c7348bd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 2 additions and 1 deletions

View File

@ -12,7 +12,7 @@ export const VitePublicDirsPlugin = createUnplugin(() => {
function resolveFromPublicAssets (id: string) {
for (const dir of nitro.options.publicAssets) {
if (!id.startsWith(withTrailingSlash(dir.baseURL || '/'))) { continue }
const path = id.replace(withTrailingSlash(dir.baseURL || '/'), withTrailingSlash(dir.dir))
const path = id.replace(/[?#].*$/, '').replace(withTrailingSlash(dir.baseURL || '/'), withTrailingSlash(dir.dir))
if (existsSync(path)) {
return id
}

View File

@ -1,6 +1,7 @@
<template>
<div>
<img src="/public.svg">
<img src="/public.svg?123">
<img src="/custom/file.svg">
</div>
</template>