Skip to content

Commit 22da71d

Browse files
fix: windows paths
1 parent 10bad26 commit 22da71d

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

packages/plugin-vite/src/mod.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { devServer } from "./plugins/dev_server.ts";
1212
import { buildIdPlugin } from "./plugins/build_id.ts";
1313
import { clientSnapshot } from "./plugins/client_snapshot.ts";
1414
import { serverSnapshot } from "./plugins/server_snapshot.ts";
15+
import { fixWindowsPaths } from "./plugins/fix_windows.ts";
1516

1617
export function fresh(config?: FreshViteConfig): Plugin[] {
1718
const fConfig: ResolvedFreshViteConfig = {
@@ -110,6 +111,7 @@ export function fresh(config?: FreshViteConfig): Plugin[] {
110111
"topLevelAwait",
111112
],
112113
}),
114+
fixWindowsPaths(),
113115
deno(),
114116
];
115117
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import type { Plugin } from "vite";
2+
3+
// Vite by default uses `C:/` style paths on windows. When you return
4+
// `C:\\` paths you may end up with duplicated modules across chunks...
5+
export function fixWindowsPaths(): Plugin {
6+
return {
7+
name: "fresh:fix-windows",
8+
enforce: "pre",
9+
async resolveId(id, importer, options) {
10+
if (Deno.build.os !== "windows") return;
11+
12+
const resolved = await this.resolve(id, importer, options);
13+
14+
if (resolved && /^[\w]+:\\/.test(resolved.id)) {
15+
resolved.id = resolved.id.replaceAll(/[\\/]+/g, "/");
16+
return resolved;
17+
}
18+
},
19+
};
20+
}

0 commit comments

Comments
 (0)