Skip to content

Commit a930638

Browse files
committed
client build entrypoints
1 parent a130e68 commit a930638

3 files changed

Lines changed: 34 additions & 23 deletions

File tree

packages/start/src/config/fs-routes/fs-watcher.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import type {
66
PluginOption,
77
ViteDevServer
88
} from "vite";
9-
import { moduleId, RouterBuilder } from "./index.js";
9+
import { moduleId } from "./index.js";
10+
import { BaseFileSystemRouter } from "./router.js";
1011

1112
interface CompiledRouter {
1213
removeRoute(path: string): void;
@@ -60,7 +61,7 @@ function createRoutesReloader(
6061
}
6162

6263
export const fileSystemWatcher = (
63-
routers: Record<"client" | "server", RouterBuilder>
64+
routers: Record<"client" | "server", BaseFileSystemRouter>
6465
): PluginOption => {
6566
const plugin: PluginOption = {
6667
name: "fs-watcher",

packages/start/src/config/fs-routes/index.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@ import { treeShake } from "./tree-shake.js";
77

88
export const moduleId = "solid-start:routes";
99

10-
export type RouterBuilder = (config: ResolvedConfig) => BaseFileSystemRouter;
11-
1210
export interface FsRoutesArgs {
13-
routers: Record<"client" | "server", RouterBuilder>;
11+
routers: Record<"client" | "server", BaseFileSystemRouter>;
1412
}
1513

1614
export function fsRoutes({ routers }: FsRoutesArgs): Array<PluginOption> {
17-
(globalThis as any).ROUTERS = {};
15+
(globalThis as any).ROUTERS = routers;
1816

1917
return [
2018
{
@@ -23,14 +21,6 @@ export function fsRoutes({ routers }: FsRoutesArgs): Array<PluginOption> {
2321
resolveId(id) {
2422
if (id === moduleId) return id;
2523
},
26-
configResolved(config) {
27-
Object.keys(routers).forEach((environment) => {
28-
const router = routers[environment as keyof typeof routers](
29-
config,
30-
);
31-
(globalThis as any).ROUTERS[environment] = router;
32-
})
33-
},
3424
async load(id) {
3525
const root = this.environment.config.root;
3626
const isBuild = this.environment.mode === "build";

packages/start/src/config/index.ts

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
ssrEntryFile,
1919
type UserNitroConfig
2020
} from "./nitroPlugin.js";
21+
import { BaseFileSystemRouter } from "./fs-routes/router.js";
2122

2223
const DEFAULT_EXTENSIONS = ["js", "jsx", "ts", "tsx"];
2324

@@ -112,6 +113,8 @@ function solidStartVitePlugin(options?: SolidStartOptions): Array<PluginOption>
112113
server: `${start.appRoot}/entry-server${entryExtension}`
113114
};
114115

116+
const root = process.cwd();
117+
115118
return [
116119
{
117120
name: "solid-start:vite-config",
@@ -123,7 +126,24 @@ function solidStartVitePlugin(options?: SolidStartOptions): Array<PluginOption>
123126
}
124127
};
125128
},
126-
config(_, env) {
129+
async config(_, env) {
130+
let clientInput = [handlers.client];
131+
132+
if (env.command === "build") {
133+
const clientRouter: BaseFileSystemRouter = (globalThis as any).ROUTERS.client
134+
for (const route of await clientRouter.getRoutes()) {
135+
for (const [key, value] of Object.entries(route)) {
136+
if (value && key.startsWith("$") && !key.startsWith("$$")) {
137+
function toRouteId(route: any) {
138+
return `${route.src}?${route.pick.map((p: string) => `pick=${p}`).join("&")}`;
139+
}
140+
141+
clientInput.push(toRouteId(value));
142+
}
143+
}
144+
}
145+
}
146+
127147
return {
128148
base: env.command === "build" ? `/${CLIENT_BASE_PATH}` : undefined,
129149
environments: {
@@ -134,13 +154,13 @@ function solidStartVitePlugin(options?: SolidStartOptions): Array<PluginOption>
134154
write: true,
135155
manifest: true,
136156
rollupOptions: {
137-
input: {
138-
client: handlers.client
139-
},
157+
input: clientInput,
140158
output: {
141159
dir: path.resolve(process.cwd(), clientDistDir, CLIENT_BASE_PATH)
142160
},
143-
external: ["node:fs", "node:path", "node:os", "node:crypto"]
161+
external: ["node:fs", "node:path", "node:os", "node:crypto"],
162+
treeshake: true,
163+
preserveEntrySignatures: "exports-only",
144164
}
145165
}
146166
},
@@ -196,14 +216,14 @@ function solidStartVitePlugin(options?: SolidStartOptions): Array<PluginOption>
196216
css(),
197217
fsRoutes({
198218
routers: {
199-
client: config =>
219+
client:
200220
new SolidStartClientFileRouter({
201-
dir: absolute(routeDir, config.root),
221+
dir: absolute(routeDir, root),
202222
extensions
203223
}),
204-
server: config =>
224+
server:
205225
new SolidStartServerFileRouter({
206-
dir: absolute(routeDir, config.root),
226+
dir: absolute(routeDir, root),
207227
extensions,
208228
dataOnly: !start.ssr
209229
})

0 commit comments

Comments
 (0)