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,11 @@ 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" ,
76- getManifest : "solid-start:get-manifest" ,
7775 middleware : "solid-start:middleware"
7876} as const ;
7977
80- export const CLIENT_BASE_PATH = "_build" ;
81-
8278function solidStartVitePlugin ( options ?: SolidStartOptions ) : Array < PluginOption > {
8379 const start = defu ( options ?? { } , {
8480 appRoot : "./src" ,
@@ -127,7 +123,7 @@ function solidStartVitePlugin(options?: SolidStartOptions): Array<PluginOption>
127123 } ;
128124 } ,
129125 async config ( _ , env ) {
130- let clientInput = [ handlers . client ] ;
126+ const clientInput = [ handlers . client ] ;
131127
132128 if ( env . command === "build" ) {
133129 const clientRouter : BaseFileSystemRouter = ( globalThis as any ) . ROUTERS . client
@@ -168,8 +164,6 @@ function solidStartVitePlugin(options?: SolidStartOptions): Array<PluginOption>
168164 consumer : "server" ,
169165 build : {
170166 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
173167 write : true ,
174168 manifest : true ,
175169 copyPublicDir : false ,
@@ -244,46 +238,36 @@ function solidStartVitePlugin(options?: SolidStartOptions): Array<PluginOption>
244238 name : "solid-start:manifest-plugin" ,
245239 enforce : "pre" ,
246240 async resolveId ( id ) {
247- if ( id === VIRTUAL_MODULES . serverManifest ) return `\0${ VIRTUAL_MODULES . serverManifest } ` ;
241+ if ( id === VIRTUAL_MODULES . clientViteManifest ) return `\0${ VIRTUAL_MODULES . clientViteManifest } ` ;
248242 if ( id === VIRTUAL_MODULES . getClientManifest )
249243 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 ;
256244 if ( id === VIRTUAL_MODULES . middleware ) {
257245 if ( start . middleware ) return await this . resolve ( start . middleware ) ;
258246
259247 return `\0${ VIRTUAL_MODULES . middleware } ` ;
260248 }
261249 } ,
262250 async load ( id ) {
263- if ( id === `\0${ VIRTUAL_MODULES . serverManifest } ` ) {
251+ if ( id === `\0${ VIRTUAL_MODULES . clientViteManifest } ` ) {
252+ let clientViteManifest : Record < string , Record < string , any > > ;
253+
264254 if ( this . environment . config . command === "serve" ) {
265- const manifest : StartServerManifest = {
266- clientViteManifest : { } ,
267- } ;
255+ clientViteManifest = { } ;
256+ } else {
257+ const entry = Object . values ( globalThis . START_CLIENT_BUNDLE ) . find (
258+ v => "isEntry" in v && v . isEntry
259+ ) ;
260+ if ( ! entry ) throw new Error ( "No client entry found" ) ;
268261
269- return `export const manifest = ${ JSON . stringify ( manifest ) } ` ;
262+ clientViteManifest = JSON . parse (
263+ ( globalThis . START_CLIENT_BUNDLE [ ".vite/manifest.json" ] as any ) . source
264+ ) ;
270265 }
271266
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" ) ) {
267+ return `export const clientViteManifest = ${ JSON . stringify ( clientViteManifest ) } ;` ;
268+ }
269+ else if ( id === `\0${ VIRTUAL_MODULES . middleware } ` ) return "export default {};"
270+ else if ( id . startsWith ( "/@manifest" ) ) {
287271 const [ path , query ] = id . split ( "?" ) ;
288272 const params = new URLSearchParams ( query ) ;
289273 if ( ! path || ! query ) return ;
@@ -296,7 +280,7 @@ function solidStartVitePlugin(options?: SolidStartOptions): Array<PluginOption>
296280 await getSsrDevManifest ( "server" ) . getAssets ( id )
297281 ) } `;
298282 }
299- } else if ( id === `\0 ${ VIRTUAL_MODULES . middleware } ` ) return "export default {};"
283+ }
300284 }
301285 } ,
302286 nitroPlugin ( { root : process . cwd ( ) } , ( ) => ssrBundle , start . server ) ,
0 commit comments