Skip to content

Commit bebecf5

Browse files
authored
Merge pull request #8 from Obad94/fix-windows-fs-path
fix(vite): correct /@fs path and cross-platform relative fallback on Windows (#7)
2 parents b9ef64c + bd7475d commit bebecf5

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

vite.config.mts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@ function buildInputs() {
1212
);
1313
}
1414

15-
const toFs = (abs: string) => "/@fs" + abs.replace(/\\/g, "/");
16-
17-
const toServerRoot = (abs: string) =>
18-
"./" + path.posix.relative(process.cwd(), abs).replace(/\\/g, "/");
15+
const toFs = (abs: string) => "/@fs/" + abs.replace(/\\/g, "/");
16+
17+
const toServerRoot = (abs: string) => {
18+
const rel = path.relative(process.cwd(), abs).replace(/\\/g, "/");
19+
// If it's not really relative (different drive or absolute), fall back to fs URL
20+
if (!rel || rel.startsWith("..") || path.isAbsolute(rel)) return toFs(abs);
21+
return "./" + rel;
22+
};
1923

2024
function multiEntryDevEndpoints(options: {
2125
entries: Record<string, string>;

0 commit comments

Comments
 (0)