Skip to content

Commit b866a55

Browse files
committed
fix(vite): keep Vite's query on ?raw imports that stay off /ns/m
A ?raw import resolved outside the project and workspace roots stays a /@fs URL served by Vite itself, so it must keep ?import&raw rather than be stripped to the bare file.
1 parent ba7ed2d commit b866a55

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

‎packages/vite/hmr/server/rewrite-imports.spec.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ describe('rewriteImports — ?raw imports', () => {
6666
expect(out).not.toContain('const icons =');
6767
});
6868

69+
it('keeps the full Vite query on a ?raw /@fs URL that stays with Vite', () => {
70+
const out = rewrite(`import svg from "/@fs/outside-roots/lib/icon.svg?import&raw";\n`);
71+
expect(out).toContain(`from "/@fs/outside-roots/lib/icon.svg?import&raw"`);
72+
});
73+
6974
it('leaves imports without ?raw as they were', () => {
7075
const out = rewrite(`import svg from "/src/icon.svg?import";\nimport icons from "/node_modules/icons/font/icons.json?import";\n`);
7176
expect(out).toContain(`from "/ns/m/src/icon.svg"`);

‎packages/vite/hmr/server/rewrite-imports.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,9 @@ export function rewriteImports(code: string, importerPath: string, sfcFileMap: M
542542
return replaceVueImport(match, prefix, spec, suffix);
543543
}
544544
const routed = replaceVueImport(match, prefix, spec.replace(PAT.QUERY_PATTERN, ''), suffix);
545-
return routed.replace(/(\/ns\/m\/[^"'?\s]+)(?=["'])/, '$1?raw');
545+
const rawRouted = routed.replace(/(\/ns\/m\/[^"'?\s]+)(?=["'])/, '$1?raw');
546+
// Only the /ns/m route serves ?raw; a URL left for Vite to serve (e.g. /@fs outside both roots) needs Vite's own query.
547+
return rawRouted !== routed ? rawRouted : replaceVueImport(match, prefix, spec, suffix);
546548
};
547549

548550
// Apply to all import/export patterns (but only .vue files will be rewritten)

0 commit comments

Comments
 (0)