@@ -352,9 +352,11 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
352352 const _library = library || ( this . get ( 'library' ) as LibraryItem [ ] ) ;
353353 const libraryAsset : AssetList = [ ] ;
354354 const libraryExportList : string [ ] = [ ] ;
355+ const functionCallLibraryExportList : string [ ] = [ ] ;
355356
356357 if ( _library && _library . length ) {
357358 _library . forEach ( ( item ) => {
359+ const { exportMode, exportSourceLibrary } = item ;
358360 this . libraryMap [ item . package ] = item . library ;
359361 if ( item . async ) {
360362 this . asyncLibraryMap [ item . package ] = item ;
@@ -364,6 +366,11 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
364366 `Object.defineProperty(window,'${ item . exportName } ',{get:()=>window.${ item . library } });` ,
365367 ) ;
366368 }
369+ if ( exportMode === 'functionCall' && exportSourceLibrary ) {
370+ functionCallLibraryExportList . push (
371+ `window["${ item . library } "] = window["${ exportSourceLibrary } "]("${ item . library } ", "${ item . package } ");` ,
372+ ) ;
373+ }
367374 if ( item . editUrls ) {
368375 libraryAsset . push ( item . editUrls ) ;
369376 } else if ( item . urls ) {
@@ -372,7 +379,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
372379 } ) ;
373380 }
374381 libraryAsset . unshift ( assetItem ( AssetType . JSText , libraryExportList . join ( '' ) ) ) ;
375-
382+ libraryAsset . push ( assetItem ( AssetType . JSText , functionCallLibraryExportList . join ( '' ) ) ) ;
376383 return libraryAsset ;
377384 }
378385
@@ -428,6 +435,9 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
428435 if ( Object . keys ( this . asyncLibraryMap ) . length > 0 ) {
429436 // 加载异步Library
430437 await renderer . loadAsyncLibrary ( this . asyncLibraryMap ) ;
438+ Object . keys ( this . asyncLibraryMap ) . forEach ( key => {
439+ delete this . asyncLibraryMap [ key ] ;
440+ } ) ;
431441 }
432442
433443 // step 5 ready & render
@@ -447,7 +457,14 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
447457
448458 async setupComponents ( library ) {
449459 const libraryAsset : AssetList = this . buildLibrary ( library ) ;
450- await this . renderer . load ( libraryAsset ) ;
460+ await this . renderer ?. load ( libraryAsset ) ;
461+ if ( Object . keys ( this . asyncLibraryMap ) . length > 0 ) {
462+ // 加载异步Library
463+ await this . renderer ?. loadAsyncLibrary ( this . asyncLibraryMap ) ;
464+ Object . keys ( this . asyncLibraryMap ) . forEach ( key => {
465+ delete this . asyncLibraryMap [ key ] ;
466+ } ) ;
467+ }
451468 }
452469
453470 setupEvents ( ) {
0 commit comments