1- import { createTanStackServerFnPlugin } from "@tanstack/server-functions-plugin" ;
2- import { defu } from "defu" ;
31import { existsSync } from "node:fs" ;
42import path , { isAbsolute , join , normalize } from "node:path" ;
53import { fileURLToPath } from "node:url" ;
6- import type { StartServerManifest } from "solid-start:server-manifest" ;
4+ import { createTanStackServerFnPlugin } from "@tanstack/server-functions-plugin" ;
5+ import { defu } from "defu" ;
76import { normalizePath , type PluginOption , type Rollup , type ViteDevServer } from "vite" ;
87import solid , { type Options as SolidOptions } from "vite-plugin-solid" ;
98
109import { isCssModulesFile } from "../server/collect-styles.js" ;
11- import { getSsrDevManifest } from "../server/manifest/dev-server -manifest.js" ;
10+ import { getSsrDevManifest } from "../server/manifest/dev-ssr -manifest.js" ;
1211import { SolidStartClientFileRouter , SolidStartServerFileRouter } from "./fs-router.js" ;
1312import { fsRoutes } from "./fs-routes/index.js" ;
13+ import type { BaseFileSystemRouter } from "./fs-routes/router.js" ;
1414import {
1515 clientDistDir ,
1616 nitroPlugin ,
1717 serverDistDir ,
1818 ssrEntryFile ,
1919 type UserNitroConfig
2020} from "./nitroPlugin.js" ;
21- import { BaseFileSystemRouter } from "./fs-routes/router .js" ;
21+ import { CLIENT_BASE_PATH } from "../constants .js" ;
2222
2323const DEFAULT_EXTENSIONS = [ "js" , "jsx" , "ts" , "tsx" ] ;
2424
@@ -70,15 +70,12 @@ const absolute = (path: string, root: string) =>
7070let ssrBundle : Rollup . OutputBundle ;
7171
7272const VIRTUAL_MODULES = {
73- serverManifest : "solid-start:server -manifest" ,
73+ clientViteManifest : "solid-start:client-vite -manifest" ,
7474 getClientManifest : "solid-start:get-client-manifest" ,
75- getSsrManifest : "solid-start:get-ssr-manifest" ,
7675 getManifest : "solid-start:get-manifest" ,
7776 middleware : "solid-start:middleware"
7877} as const ;
7978
80- export const CLIENT_BASE_PATH = "_build" ;
81-
8279function solidStartVitePlugin ( options ?: SolidStartOptions ) : Array < PluginOption > {
8380 const start = defu ( options ?? { } , {
8481 appRoot : "./src" ,
@@ -127,7 +124,7 @@ function solidStartVitePlugin(options?: SolidStartOptions): Array<PluginOption>
127124 } ;
128125 } ,
129126 async config ( _ , env ) {
130- let clientInput = [ handlers . client ] ;
127+ const clientInput = [ handlers . client ] ;
131128
132129 if ( env . command === "build" ) {
133130 const clientRouter : BaseFileSystemRouter = ( globalThis as any ) . ROUTERS . client
@@ -168,8 +165,6 @@ function solidStartVitePlugin(options?: SolidStartOptions): Array<PluginOption>
168165 consumer : "server" ,
169166 build : {
170167 ssr : true ,
171- // we don't write to the file system as the below 'capture-output' plugin will
172- // capture the output and write it to the virtual file system
173168 write : true ,
174169 manifest : true ,
175170 copyPublicDir : false ,
@@ -244,46 +239,41 @@ function solidStartVitePlugin(options?: SolidStartOptions): Array<PluginOption>
244239 name : "solid-start:manifest-plugin" ,
245240 enforce : "pre" ,
246241 async resolveId ( id ) {
247- if ( id === VIRTUAL_MODULES . serverManifest ) return `\0${ VIRTUAL_MODULES . serverManifest } ` ;
242+ if ( id === VIRTUAL_MODULES . clientViteManifest ) return `\0${ VIRTUAL_MODULES . clientViteManifest } ` ;
248243 if ( id === VIRTUAL_MODULES . getClientManifest )
249244 return new URL ( "../server/manifest/client-manifest.js" , import . meta. url ) . pathname ;
250- if ( id === VIRTUAL_MODULES . getSsrManifest )
251- return new URL ( "../server/manifest/ssr-manifest.js" , import . meta. url ) . pathname ;
252- if ( id === VIRTUAL_MODULES . getManifest )
253- return this . environment . config . consumer === "server"
254- ? new URL ( "../server/manifest/ssr-manifest.js" , import . meta. url ) . pathname
255- : new URL ( "../server/manifest/client-manifest.js" , import . meta. url ) . pathname ;
245+ if ( id === VIRTUAL_MODULES . getManifest ) {
246+ return this . environment . config . consumer === "client" ?
247+ new URL ( "../server/manifest/client-manifest.js" , import . meta. url ) . pathname :
248+ new URL ( "../server/manifest/ssr-manifest.js" , import . meta. url ) . pathname ;
249+ }
256250 if ( id === VIRTUAL_MODULES . middleware ) {
257251 if ( start . middleware ) return await this . resolve ( start . middleware ) ;
258252
259253 return `\0${ VIRTUAL_MODULES . middleware } ` ;
260254 }
261255 } ,
262256 async load ( id ) {
263- if ( id === `\0${ VIRTUAL_MODULES . serverManifest } ` ) {
257+ if ( id === `\0${ VIRTUAL_MODULES . clientViteManifest } ` ) {
258+ let clientViteManifest : Record < string , Record < string , any > > ;
259+
264260 if ( this . environment . config . command === "serve" ) {
265- const manifest : StartServerManifest = {
266- clientViteManifest : { } ,
267- } ;
261+ clientViteManifest = { } ;
262+ } else {
263+ const entry = Object . values ( globalThis . START_CLIENT_BUNDLE ) . find (
264+ v => "isEntry" in v && v . isEntry
265+ ) ;
266+ if ( ! entry ) throw new Error ( "No client entry found" ) ;
268267
269- return `export const manifest = ${ JSON . stringify ( manifest ) } ` ;
268+ clientViteManifest = JSON . parse (
269+ ( globalThis . START_CLIENT_BUNDLE [ ".vite/manifest.json" ] as any ) . source
270+ ) ;
270271 }
271272
272- const entry = Object . values ( globalThis . START_CLIENT_BUNDLE ) . find (
273- v => "isEntry" in v && v . isEntry
274- ) ;
275- if ( ! entry ) throw new Error ( "No client entry found" ) ;
276-
277- const clientManifest : Record < string , Record < string , any > > = JSON . parse (
278- ( globalThis . START_CLIENT_BUNDLE [ ".vite/manifest.json" ] as any ) . source
279- ) ;
280-
281- const manifest : StartServerManifest = {
282- clientViteManifest : clientManifest as any ,
283- } ;
284-
285- return `export const manifest = ${ JSON . stringify ( manifest ) } ;` ;
286- } else if ( id . startsWith ( "/@manifest" ) ) {
273+ return `export const clientViteManifest = ${ JSON . stringify ( clientViteManifest ) } ;` ;
274+ }
275+ else if ( id === `\0${ VIRTUAL_MODULES . middleware } ` ) return "export default {};"
276+ else if ( id . startsWith ( "/@manifest" ) ) {
287277 const [ path , query ] = id . split ( "?" ) ;
288278 const params = new URLSearchParams ( query ) ;
289279 if ( ! path || ! query ) return ;
@@ -296,7 +286,7 @@ function solidStartVitePlugin(options?: SolidStartOptions): Array<PluginOption>
296286 await getSsrDevManifest ( "server" ) . getAssets ( id )
297287 ) } `;
298288 }
299- } else if ( id === `\0 ${ VIRTUAL_MODULES . middleware } ` ) return "export default {};"
289+ }
300290 }
301291 } ,
302292 nitroPlugin ( { root : process . cwd ( ) } , ( ) => ssrBundle , start . server ) ,
0 commit comments