diff --git a/packages/plugin-vue/src/index.ts b/packages/plugin-vue/src/index.ts index 183d3ff6..c5da44e6 100644 --- a/packages/plugin-vue/src/index.ts +++ b/packages/plugin-vue/src/index.ts @@ -201,6 +201,24 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin { : createFilter(customElement) }) + function carryQueryWithSvgUse(code: string, id: string) { + if (!id.endsWith('.vue')) { + return code + } + const reg = / { + const [path, hash] = match.split(/#/) + if (!path.endsWith('.svg') || match.includes('?')) { + return match + } + if (hash) { + return `${path}?no-inline#${hash}` + } + return `${path}?no-inline` + }) + return code + } + return { name: 'vite:vue', @@ -344,6 +362,7 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin { }, transform(code, id, opt) { + code = carryQueryWithSvgUse(code, id) const ssr = opt?.ssr === true const { filename, query } = parseVueRequest(id)