@@ -96,17 +96,50 @@ function nitroEnv(ctx: NitroPluginContext): VitePlugin {
9696 ...createServiceEnvironments ( ctx ) ,
9797 nitro : createNitroEnvironment ( ctx ) ,
9898 } ;
99- environments . client = {
100- consumer : userConfig . environments ?. client ?. consumer ?? "client" ,
101- build : {
102- rollupOptions : {
103- input :
104- userConfig . environments ?. client ?. build ?. rollupOptions ?. input ??
105- useNitro ( ctx ) . options . renderer ?. template ,
106- } ,
107- } ,
108- } ;
109- debug ( "[env] Environments:" , Object . keys ( environments ) . join ( ", " ) ) ;
99+
100+ let clientEntry : string | undefined ;
101+ let clientEntryConfigured = ! ! getEntry (
102+ userConfig . environments ?. client ?. build ?. rolldownOptions ?. input ||
103+ userConfig . environments ?. client ?. build ?. rollupOptions ?. input
104+ ) ;
105+ if ( ! clientEntryConfigured ) {
106+ const rendererTemplate = useNitro ( ctx ) . options . renderer ?. template ;
107+ if ( rendererTemplate ) {
108+ // Use Nitro renderer template as client entry
109+ clientEntry = rendererTemplate ;
110+ ctx . nitro ! . logger . info (
111+ `Using Nitro renderer template \`${ prettyPath ( rendererTemplate ) } \` as vite client entry.`
112+ ) ;
113+ } else {
114+ // Auto-detect client entry
115+ clientEntry = resolveModulePath ( "./entry-client" , {
116+ try : true ,
117+ extensions : DEFAULT_EXTENSIONS ,
118+ from : [ "app" , "src" , "" ] . flatMap ( ( d ) =>
119+ [ ctx . nitro ! . options . rootDir , ...ctx . nitro ! . options . scanDirs ] . map (
120+ ( s ) => join ( s , d ) + "/"
121+ )
122+ ) ,
123+ } ) ;
124+ if ( clientEntry ) {
125+ ctx . nitro ! . logger . info ( `Using \`${ prettyPath ( clientEntry ) } \` as vite client entry.` ) ;
126+ }
127+ }
128+ }
129+ if ( clientEntry ) {
130+ environments . client = {
131+ consumer : userConfig . environments ?. client ?. consumer ?? "client" ,
132+ build : clientEntryConfigured
133+ ? undefined
134+ : {
135+ rollupOptions : {
136+ input : clientEntry ? { index : clientEntry } : undefined ,
137+ } ,
138+ } ,
139+ } ;
140+ debug ( "[env] Environments:" , Object . keys ( environments ) . join ( ", " ) ) ;
141+ }
142+
110143 return {
111144 environments,
112145 } ;
@@ -380,7 +413,10 @@ async function setupNitroContext(
380413 ctx . nitro ! . logger . info ( `Using \`${ prettyPath ( ssrEntry ) } \` as vite ssr entry.` ) ;
381414 }
382415 } else {
383- let ssrEntry = getEntry ( userConfig . environments . ssr . build ?. rollupOptions ?. input ) ;
416+ let ssrEntry = getEntry (
417+ userConfig . environments . ssr . build ?. rolldownOptions ?. input ||
418+ userConfig . environments . ssr . build ?. rollupOptions ?. input
419+ ) ;
384420 if ( typeof ssrEntry === "string" ) {
385421 ssrEntry =
386422 resolveModulePath ( ssrEntry , {
0 commit comments