@@ -56,8 +56,6 @@ export default function middleware({ App, routes, store }: {
56
56
57
57
const output = locations . dest ( ) ;
58
58
59
- const client_assets = JSON . parse ( fs . readFileSync ( path . join ( output , 'client_assets.json' ) , 'utf-8' ) ) ;
60
-
61
59
let emitted_basepath = false ;
62
60
63
61
const middleware = compose_handlers ( [
@@ -105,7 +103,7 @@ export default function middleware({ App, routes, store }: {
105
103
cache_control : 'max-age=31536000'
106
104
} ) ,
107
105
108
- get_route_handler ( client_assets , App , routes , store )
106
+ get_route_handler ( App , routes , store )
109
107
] . filter ( Boolean ) ) ;
110
108
111
109
return middleware ;
@@ -148,7 +146,13 @@ function serve({ prefix, pathname, cache_control }: {
148
146
} ;
149
147
}
150
148
151
- function get_route_handler ( chunks : Record < string , string > , App : Component , routes : RouteObject [ ] , store_getter : ( req : Req ) => Store ) {
149
+ function get_route_handler ( App : Component , routes : RouteObject [ ] , store_getter : ( req : Req ) => Store ) {
150
+ const output = locations . dest ( ) ;
151
+
152
+ const get_chunks = dev ( )
153
+ ? ( ) => JSON . parse ( fs . readFileSync ( path . join ( output , 'client_assets.json' ) , 'utf-8' ) )
154
+ : ( assets => ( ) => assets ) ( JSON . parse ( fs . readFileSync ( path . join ( output , 'client_assets.json' ) , 'utf-8' ) ) ) ;
155
+
152
156
const template = dev ( )
153
157
? ( ) => fs . readFileSync ( `${ locations . app ( ) } /template.html` , 'utf-8' )
154
158
: ( str => ( ) => str ) ( fs . readFileSync ( `${ locations . dest ( ) } /template.html` , 'utf-8' ) ) ;
@@ -159,6 +163,8 @@ function get_route_handler(chunks: Record<string, string>, App: Component, route
159
163
const handlers = route . handlers [ Symbol . iterator ] ( ) ;
160
164
161
165
function next ( ) {
166
+ const chunks : Record < string , string > = get_chunks ( ) ;
167
+
162
168
try {
163
169
const { value : handler , done } = handlers . next ( ) ;
164
170
@@ -384,7 +390,7 @@ function get_route_handler(chunks: Record<string, string>, App: Component, route
384
390
function render_page ( { head, css, html } ) {
385
391
const page = template ( )
386
392
. replace ( '%sapper.base%' , `<base href="${ req . baseUrl } /">` )
387
- . replace ( '%sapper.scripts%' , `<script>__SAPPER__={baseUrl: "${ req . baseUrl } "}</script><script src='${ req . baseUrl } /client/${ chunks . main } '></script>` )
393
+ . replace ( '%sapper.scripts%' , `<script>__SAPPER__={baseUrl: "${ req . baseUrl } "}</script><script src='${ req . baseUrl } /client/${ get_chunks ( ) . main } '></script>` )
388
394
. replace ( '%sapper.html%' , html )
389
395
. replace ( '%sapper.head%' , `<noscript id='sapper-head-start'></noscript>${ head } <noscript id='sapper-head-end'></noscript>` )
390
396
. replace ( '%sapper.styles%' , ( css && css . code ? `<style>${ css . code } </style>` : '' ) ) ;
0 commit comments