Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/vite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,12 +319,12 @@ export function fileRoutes(options: FileRoutesOptions = {}): PluginOption[] {
// plus the `src` lazy refs already expose.
if (!codeSplitting) {
return {
src: relative(root, buildId),
src: normalizePath(relative(root, buildId)),
require: `_$() => (${js.addNamespaceImport(buildId)})$_`
};
}
return {
src: relative(root, buildId),
src: normalizePath(relative(root, buildId)),
build: isBuild ? `_$() => import('${buildId}')$_` : undefined,
import: `_$() => import('${buildId}')$_`
};
Expand Down
14 changes: 14 additions & 0 deletions test/vite.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,20 @@ describe("fileRoutes vite plugin", () => {
expect(code.match(/pick=default&pick=\$css&lang\.tsx'\)/g)?.length).toBe(2);
});

it("serializes lazy-ref src values with forward slashes", async () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this actually test something with forward slashes or am i missing something

const directory = createRouteTree({
"index.tsx": "export default () => <h1>Home</h1>;"
});

const split = await loadVirtualModule(directory);
const eager = await loadWith(createPlugin(directory, { codeSplitting: false }), directory);

expect(split).toContain('"src"');
expect(eager).toContain('"src"');
expect(split).not.toContain("\\");
expect(eager).not.toContain("\\");
});

it("resolves only the virtual module id", async () => {
const [plugin] = fileRoutes() as any[];
expect(moduleId).toBe("virtual:file-routes");
Expand Down
Loading