File tree Expand file tree Collapse file tree 3 files changed +33
-2
lines changed
server/prod-server/src/libs/render
solutions/app-tools/src/analyze Expand file tree Collapse file tree 3 files changed +33
-2
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' @modern-js/app-tools ' : patch
3
+ ' @modern-js/prod-server ' : patch
4
+ ---
5
+
6
+ feat: ssr mode support async entry
7
+ feat: ssr 模式支持异步入口
Original file line number Diff line number Diff line change @@ -81,7 +81,8 @@ export const render = async (
81
81
context . metrics = createMetrics ( context , ctx . metrics ) ;
82
82
83
83
runner . extendSSRContext ( context ) ;
84
- const serverRender = require ( bundleJS ) [ SERVER_RENDER_FUNCTION_NAME ] ;
84
+ const bundleJSContent = await Promise . resolve ( require ( bundleJS ) ) ;
85
+ const serverRender = bundleJSContent [ SERVER_RENDER_FUNCTION_NAME ] ;
85
86
const content = await cache ( serverRender , ctx ) ( context ) ;
86
87
87
88
const { url, status = 302 } = context . redirection ;
Original file line number Diff line number Diff line change 6
6
isSSGEntry ,
7
7
isUseSSRBundle ,
8
8
logger ,
9
+ SERVER_RENDER_FUNCTION_NAME ,
9
10
} from '@modern-js/utils' ;
10
11
import { IAppContext , PluginAPI } from '@modern-js/core' ;
11
12
import type {
@@ -285,9 +286,31 @@ export const generateCode = async (
285
286
286
287
// generate entry file.
287
288
if ( config . source . enableAsyncEntry ) {
289
+ let rawAsyncEntryCode = `import('./${ ENTRY_BOOTSTRAP_FILE_NAME } ');` ;
290
+ const ssr = getEntryOptions (
291
+ entryName ,
292
+ config . server . ssr ,
293
+ config . server . ssrByEntries ,
294
+ packageName ,
295
+ ) ;
296
+ if ( ssr ) {
297
+ rawAsyncEntryCode = `
298
+ export const ${ SERVER_RENDER_FUNCTION_NAME } = async (...args) => {
299
+ let entry = await ${ rawAsyncEntryCode } ;
300
+ if (entry.default instanceof Promise){
301
+ entry = await entry.default;
302
+ return entry.default.${ SERVER_RENDER_FUNCTION_NAME } .apply(null, args);
303
+ }
304
+ return entry.${ SERVER_RENDER_FUNCTION_NAME } .apply(null, args);
305
+ };
306
+ if(typeof window!=='undefined'){
307
+ ${ rawAsyncEntryCode }
308
+ }
309
+ ` ;
310
+ }
288
311
const { code : asyncEntryCode } = await hookRunners . modifyAsyncEntry ( {
289
312
entrypoint,
290
- code : `import('./ ${ ENTRY_BOOTSTRAP_FILE_NAME } ');` ,
313
+ code : rawAsyncEntryCode ,
291
314
} ) ;
292
315
fs . outputFileSync ( entryFile , asyncEntryCode , 'utf8' ) ;
293
316
You can’t perform that action at this time.
0 commit comments