11import { existsSync } from "node:fs" ;
22import path , { isAbsolute , join , normalize } from "node:path" ;
33import { fileURLToPath } from "node:url" ;
4- import { createTanStackServerFnPlugin } from "@tanstack/server-functions-plugin" ;
4+ import { TanStackServerFnPluginEnv } from "@tanstack/server-functions-plugin" ;
55import { defu } from "defu" ;
66import { normalizePath , type PluginOption , type Rollup , type ViteDevServer } from "vite" ;
77import solid , { type Options as SolidOptions } from "vite-plugin-solid" ;
88
9+ import { CLIENT_BASE_PATH , DEFAULT_EXTENSIONS , VIRTUAL_MODULES } from "../constants.js" ;
910import { isCssModulesFile } from "../server/collect-styles.js" ;
1011import { getSsrDevManifest } from "../server/manifest/dev-ssr-manifest.js" ;
1112import { SolidStartClientFileRouter , SolidStartServerFileRouter } from "./fs-router.js" ;
@@ -18,9 +19,6 @@ import {
1819 ssrEntryFile ,
1920 type UserNitroConfig
2021} from "./nitroPlugin.js" ;
21- import { CLIENT_BASE_PATH } from "../constants.js" ;
22-
23- const DEFAULT_EXTENSIONS = [ "js" , "jsx" , "ts" , "tsx" ] ;
2422
2523export type { UserNitroConfig } from "./nitroPlugin.js" ;
2624
@@ -33,49 +31,12 @@ export interface SolidStartOptions {
3331 middleware ?: string ;
3432}
3533
36- const SolidStartServerFnsPlugin = createTanStackServerFnPlugin ( {
37- // This is the ID that will be available to look up and import
38- // our server function manifest and resolve its module
39- manifestVirtualImportId : "solidstart:server-fn-manifest" ,
40- client : {
41- getRuntimeCode : ( ) =>
42- `import { createServerReference } from "${ normalize (
43- fileURLToPath ( new URL ( "../server/server-runtime.js" , import . meta. url ) )
44- ) } "`,
45- replacer : opts =>
46- `createServerReference(${ ( ) => { } } , '${ opts . functionId } ', '${ opts . extractedFilename } ')`
47- } ,
48- ssr : {
49- getRuntimeCode : ( ) =>
50- `import { createServerReference } from '${ normalize (
51- fileURLToPath ( new URL ( "../server/server-fns-runtime.js" , import . meta. url ) )
52- ) } '`,
53- replacer : opts =>
54- `createServerReference(${ opts . fn } , '${ opts . functionId } ', '${ opts . extractedFilename } ')`
55- } ,
56- server : {
57- getRuntimeCode : ( ) =>
58- `import { createServerReference } from '${ normalize (
59- fileURLToPath ( new URL ( "../server/server-fns-runtime.js" , import . meta. url ) )
60- ) } '`,
61- replacer : opts =>
62- `createServerReference(${ opts . fn } , '${ opts . functionId } ', '${ opts . extractedFilename } ')`
63- }
64- } ) ;
65-
6634const absolute = ( path : string , root : string ) =>
6735 path ? ( isAbsolute ( path ) ? path : join ( root , path ) ) : path ;
6836
6937// this needs to live outside of the TanStackStartVitePlugin since it will be invoked multiple times by vite
7038let ssrBundle : Rollup . OutputBundle ;
7139
72- const VIRTUAL_MODULES = {
73- clientViteManifest : "solid-start:client-vite-manifest" ,
74- getClientManifest : "solid-start:get-client-manifest" ,
75- getManifest : "solid-start:get-manifest" ,
76- middleware : "solid-start:middleware"
77- } as const ;
78-
7940function solidStartVitePlugin ( options ?: SolidStartOptions ) : Array < PluginOption > {
8041 const start = defu ( options ?? { } , {
8142 appRoot : "./src" ,
@@ -227,14 +188,27 @@ function solidStartVitePlugin(options?: SolidStartOptions): Array<PluginOption>
227188 } ) ,
228189 // Must be placed after fsRoutes, as treeShake will remove the
229190 // server fn exports added in by this plugin
230- {
231- name : "solid-start:server-fns" ,
232- enforce : "pre" ,
233- applyToEnvironment ( env ) {
234- if ( env . name === "server" ) return SolidStartServerFnsPlugin . server ;
235- return SolidStartServerFnsPlugin . client ;
191+ TanStackServerFnPluginEnv ( {
192+ // This is the ID that will be available to look up and import
193+ // our server function manifest and resolve its module
194+ manifestVirtualImportId : VIRTUAL_MODULES . serverFnManifest ,
195+ client : {
196+ getRuntimeCode : ( ) =>
197+ `import { createServerReference } from "${ normalize (
198+ fileURLToPath ( new URL ( "../server/server-runtime.js" , import . meta. url ) )
199+ ) } "`,
200+ replacer : opts =>
201+ `createServerReference(${ ( ) => { } } , '${ opts . functionId } ', '${ opts . extractedFilename } ')`
202+ } ,
203+ server : {
204+ getRuntimeCode : ( ) =>
205+ `import { createServerReference } from '${ normalize (
206+ fileURLToPath ( new URL ( "../server/server-fns-runtime.js" , import . meta. url ) )
207+ ) } '`,
208+ replacer : opts =>
209+ `createServerReference(${ opts . fn } , '${ opts . functionId } ', '${ opts . extractedFilename } ')`
236210 }
237- } ,
211+ } ) ,
238212 {
239213 name : "solid-start:manifest-plugin" ,
240214 enforce : "pre" ,
0 commit comments