@@ -20,106 +20,120 @@ export type UserNitroConfig = Omit<
2020> ;
2121
2222export function nitroV2Plugin ( nitroConfig ?: UserNitroConfig ) : PluginOption {
23- return {
24- name : "solid-start-vite-plugin-nitro" ,
25- generateBundle : {
26- handler ( _options , bundle ) {
27- if ( this . environment . name !== "ssr" ) {
28- return ;
29- }
30-
31- // find entry point of ssr bundle
32- let entryFile : string | undefined ;
33- for ( const [ _name , file ] of Object . entries ( bundle ) ) {
34- if ( file . type === "chunk" ) {
35- if ( file . isEntry ) {
36- if ( entryFile !== undefined ) {
37- this . error (
38- `Multiple entry points found for service "${ this . environment . name } ". Only one entry point is allowed.` ,
39- ) ;
40- }
41- entryFile = file . fileName ;
42- }
43- }
44- }
45- if ( entryFile === undefined ) {
46- this . error (
47- `No entry point found for service "${ this . environment . name } ".` ,
48- ) ;
49- }
50- ssrEntryFile = entryFile ! ;
51- ssrBundle = bundle ;
52- } ,
53- } ,
54- config ( ) {
55- return {
56- environments : {
57- ssr : {
58- consumer : "server" ,
59- build : {
60- commonjsOptions : {
61- include : [ ] ,
62- } ,
63- ssr : true ,
64- sourcemap : true ,
65- } ,
66- } ,
67- } ,
68- builder : {
69- sharedPlugins : true ,
70- async buildApp ( builder ) {
71- const client = builder . environments . client ;
72- const server = builder . environments . ssr ;
73-
74- if ( ! client ) throw new Error ( "Client environment not found" ) ;
75- if ( ! server ) throw new Error ( "SSR environment not found" ) ;
76-
77- await builder . build ( client ) ;
78- await builder . build ( server ) ;
79-
80- const virtualEntry = "#solid-start/entry" ;
81- const resolvedNitroConfig : NitroConfig = {
82- compatibilityDate : "2024-11-19" ,
83- logLevel : 3 ,
84- preset : "node-server" ,
85- typescript : {
86- generateTsConfig : false ,
87- generateRuntimeConfigTypes : false ,
88- } ,
89- ...nitroConfig ,
90- dev : false ,
91- publicAssets : [
92- {
93- dir : client . config . build . outDir ,
94- maxAge : 31536000 , // 1 year
95- baseURL : "/" ,
96- } ,
97- ] ,
98- renderer : virtualEntry ,
99- rollupConfig : {
100- ...nitroConfig ?. rollupConfig ,
101- plugins : [ virtualBundlePlugin ( ssrBundle ) as any ] ,
102- } ,
103- experimental : {
104- ...nitroConfig ?. experimental ,
105- asyncContext : true ,
106- } ,
107- virtual : {
108- ...nitroConfig ?. virtual ,
109- [ virtualEntry ] : `import { fromWebHandler } from 'h3'
110- import handler from '${ ssrEntryFile } '
111- export default fromWebHandler(handler.fetch)` ,
112- } ,
113- } ;
114-
115- const nitro = await createNitro ( resolvedNitroConfig ) ;
116-
117- await buildNitroEnvironment ( nitro , ( ) => build ( nitro ) ) ;
118- } ,
119- } ,
120- } ;
121- } ,
122- } ;
23+ return [
24+ {
25+ name : "solid-start-vite-plugin-nitro" ,
26+ generateBundle : {
27+ handler ( _options , bundle ) {
28+ if ( this . environment . name !== "ssr" ) {
29+ return ;
30+ }
31+
32+ // find entry point of ssr bundle
33+ let entryFile : string | undefined ;
34+ for ( const [ _name , file ] of Object . entries ( bundle ) ) {
35+ if ( file . type === "chunk" ) {
36+ if ( file . isEntry ) {
37+ if ( entryFile !== undefined ) {
38+ this . error (
39+ `Multiple entry points found for service "${ this . environment . name } ". Only one entry point is allowed.` ,
40+ ) ;
41+ }
42+ entryFile = file . fileName ;
43+ }
44+ }
45+ }
46+ if ( entryFile === undefined ) {
47+ this . error (
48+ `No entry point found for service "${ this . environment . name } ".` ,
49+ ) ;
50+ }
51+ ssrEntryFile = entryFile ! ;
52+ ssrBundle = bundle ;
53+ } ,
54+ } ,
55+ config ( ) {
56+ return {
57+ environments : {
58+ ssr : {
59+ consumer : "server" ,
60+ build : {
61+ commonjsOptions : {
62+ include : [ ] ,
63+ } ,
64+ ssr : true ,
65+ sourcemap : true ,
66+ } ,
67+ } ,
68+ } ,
69+ builder : {
70+ sharedPlugins : true ,
71+ async buildApp ( builder ) {
72+ const client = builder . environments . client ;
73+ const server = builder . environments . ssr ;
74+
75+ if ( ! client ) throw new Error ( "Client environment not found" ) ;
76+ if ( ! server ) throw new Error ( "SSR environment not found" ) ;
77+
78+ await builder . build ( client ) ;
79+ await builder . build ( server ) ;
80+
81+ const virtualEntry = "#solid-start/entry" ;
82+ const resolvedNitroConfig : NitroConfig = {
83+ compatibilityDate : "2024-11-19" ,
84+ logLevel : 3 ,
85+ preset : "node-server" ,
86+ typescript : {
87+ generateTsConfig : false ,
88+ generateRuntimeConfigTypes : false ,
89+ } ,
90+ ...nitroConfig ,
91+ dev : false ,
92+ publicAssets : [
93+ {
94+ dir : client . config . build . outDir ,
95+ maxAge : 31536000 , // 1 year
96+ baseURL : "/" ,
97+ } ,
98+ ] ,
99+ renderer : virtualEntry ,
100+ rollupConfig : {
101+ ...nitroConfig ?. rollupConfig ,
102+ plugins : [ virtualBundlePlugin ( ssrBundle ) as any ] ,
103+ } ,
104+ experimental : {
105+ ...nitroConfig ?. experimental ,
106+ asyncContext : true ,
107+ } ,
108+ virtual : {
109+ ...nitroConfig ?. virtual ,
110+ [ virtualEntry ] : `import { fromWebHandler } from 'h3'
111+ import handler from '${ ssrEntryFile } '
112+ export default fromWebHandler(handler.fetch)` ,
113+ } ,
114+ } ;
115+
116+ const nitro = await createNitro ( resolvedNitroConfig ) ;
117+
118+ await buildNitroEnvironment ( nitro , ( ) => build ( nitro ) ) ;
119+ } ,
120+ } ,
121+ } ;
122+ } ,
123+ } ,
124+ nitroConfig ?. preset === "netlify" && {
125+ name : "solid-start-nitro-netlify-fix" ,
126+ enforce : "post" ,
127+ config ( ) {
128+ return {
129+ environments : {
130+ client : { build : { outDir : ".solid-start/client" } } ,
131+ ssr : { build : { outDir : ".solid-start/server" } }
132+ }
133+ }
134+ }
135+ }
136+ ] ;
123137}
124138
125139export async function buildNitroEnvironment (
0 commit comments