@@ -153,8 +153,7 @@ public override bool Execute()
153
153
BuildServiceWorkers ( ) ;
154
154
GenerateEmbeddedJs ( ) ;
155
155
GenerateIndexHtml ( ) ;
156
- GenerateConfig ( ) ;
157
- GenerateConfigScript ( ) ;
156
+ GenerateConfigFiles ( ) ;
158
157
RemoveDuplicateAssets ( ) ;
159
158
}
160
159
finally
@@ -531,112 +530,18 @@ static string BuildDependencyPath(string dep, string baseLookup)
531
530
? $ "\" { baseLookup } { Path . GetFileName ( dep ) } \" "
532
531
: $ "\" { baseLookup } { Path . GetFileNameWithoutExtension ( dep ) } \" ";
533
532
534
- private void GenerateConfig ( )
533
+ private void GenerateConfigFiles ( )
535
534
{
536
- var unoConfigJsPath = Path . Combine ( _intermediateAssetsPath , "uno-config.js" ) ;
535
+ GenerateConfigFile ( "uno-config.js" , isModule : true ) ;
537
536
538
- using ( var w = new StreamWriter ( unoConfigJsPath , false , _utf8Encoding ) )
539
- {
540
- var baseLookup = _shellMode == ShellMode . Node ? "" : $ "{ WebAppBasePath } { PackageAssetsFolder } /";
541
- var dependencies = string . Join ( ", " , _dependencies
542
- . Where ( d =>
543
- ! d . EndsWith ( "require.js" )
544
- && ! d . EndsWith ( "uno-bootstrap.js" )
545
- && ! d . EndsWith ( "service-worker.js" )
546
- && ! d . EndsWith ( "service-worker-classic.js" ) )
547
- . Select ( dep => BuildDependencyPath ( dep , baseLookup ) ) ) ;
548
-
549
- var config = new StringBuilder ( ) ;
550
-
551
- var enablePWA = ! string . IsNullOrEmpty ( PWAManifestFile ) ;
552
-
553
- var sanitizedOfflineFiles = StaticWebContent
554
- . Select ( f => f . GetMetadata ( "Link" )
555
- . Replace ( "\\ " , "/" )
556
- . Replace ( "wwwroot/" , "" ) )
557
- . Concat ( [ $ "uno-config.js", "_framework/blazor.boot.json" , "." ] ) ;
558
-
559
- var offlineFiles = enablePWA ? string . Join ( ", " , sanitizedOfflineFiles . Select ( f => $ "\" { WebAppBasePath } { f } \" ") ) : "" ;
560
-
561
- var emccExportedRuntimeMethodsParams = string . Join (
562
- "," ,
563
- GetEmccExportedRuntimeMethods ( ) . Select ( f => $ "\' { f } \' ") ) ;
564
-
565
- var runtimeOptionsSet = string . Join ( "," , ( RuntimeOptions ? . Split ( ' ' ) ?? [ ] ) . Select ( f => $ "\' { f } \' ") ) ;
566
-
567
- config . AppendLine ( $ "let config = {{}};") ;
568
- config . AppendLine ( $ "config.uno_remote_managedpath = \" _framework\" ;") ;
569
- config . AppendLine ( $ "config.uno_app_base = \" { WebAppBasePath } { PackageAssetsFolder } \" ;") ;
570
- config . AppendLine ( $ "config.uno_dependencies = [{ dependencies } ];") ;
571
- config . AppendLine ( $ "config.uno_runtime_options = [{ runtimeOptionsSet } ];") ;
572
- config . AppendLine ( $ "config.enable_pwa = { enablePWA . ToString ( ) . ToLowerInvariant ( ) } ;") ;
573
- config . AppendLine ( $ "config.offline_files = ['{ WebAppBasePath } ', { offlineFiles } ];") ;
574
- config . AppendLine ( $ "config.uno_shell_mode = \" { _shellMode } \" ;") ;
575
- config . AppendLine ( $ "config.uno_debugging_enabled = { ( ! Optimize ) . ToString ( ) . ToLowerInvariant ( ) } ;") ;
576
- config . AppendLine ( $ "config.uno_enable_tracing = { EnableTracing . ToString ( ) . ToLowerInvariant ( ) } ;") ;
577
- config . AppendLine ( $ "config.uno_load_all_satellite_resources = { LoadAllSatelliteResources . ToString ( ) . ToLowerInvariant ( ) } ;") ;
578
- config . AppendLine ( $ "config.emcc_exported_runtime_methods = [{ emccExportedRuntimeMethodsParams } ];") ;
579
-
580
- if ( GenerateAOTProfile )
581
- {
582
- config . AppendLine ( $ "config.generate_aot_profile = true;") ;
583
- }
584
-
585
- config . AppendLine ( $ "config.environmentVariables = config.environmentVariables || {{}};") ;
586
-
587
- void AddEnvironmentVariable ( string name , string value ) => config . AppendLine ( $ "config.environmentVariables[\" { name } \" ] = \" { value } \" ;") ;
588
-
589
- if ( MonoEnvironment != null )
590
- {
591
- foreach ( var env in MonoEnvironment )
592
- {
593
- AddEnvironmentVariable ( env . ItemSpec , env . GetMetadata ( "Value" ) ) ;
594
- }
595
- }
596
-
597
- var isProfiledAOT = UseAotProfile && _runtimeExecutionMode == RuntimeExecutionMode . InterpreterAndAOT ;
598
-
599
- AddEnvironmentVariable ( "UNO_BOOTSTRAP_MONO_RUNTIME_MODE" , _runtimeExecutionMode . ToString ( ) ) ;
600
- AddEnvironmentVariable ( "UNO_BOOTSTRAP_MONO_PROFILED_AOT" , isProfiledAOT . ToString ( ) ) ;
601
- AddEnvironmentVariable ( "UNO_BOOTSTRAP_LINKER_ENABLED" , ( PublishTrimmed && RunILLink ) . ToString ( ) ) ;
602
- AddEnvironmentVariable ( "UNO_BOOTSTRAP_DEBUGGER_ENABLED" , ( ! Optimize ) . ToString ( ) ) ;
603
- AddEnvironmentVariable ( "UNO_BOOTSTRAP_MONO_RUNTIME_CONFIGURATION" , "Release" ) ;
604
- AddEnvironmentVariable ( "UNO_BOOTSTRAP_MONO_RUNTIME_FEATURES" , BuildRuntimeFeatures ( ) ) ;
605
- AddEnvironmentVariable ( "UNO_BOOTSTRAP_APP_BASE" , PackageAssetsFolder ) ;
606
- AddEnvironmentVariable ( "UNO_BOOTSTRAP_WEBAPP_BASE_PATH" , WebAppBasePath ) ;
607
-
608
- if ( EmccFlags ? . Any ( f => f . ItemSpec ? . Contains ( "MAXIMUM_MEMORY=4GB" ) ?? false ) ?? false )
609
- {
610
- // Detects the use of the 4GB flag: https://v8.dev/blog/4gb-wasm-memory
611
- AddEnvironmentVariable ( "UNO_BOOTSTRAP_EMSCRIPTEN_MAXIMUM_MEMORY" , "4GB" ) ;
612
- }
613
-
614
- if ( EnableLogProfiler )
615
- {
616
- AddEnvironmentVariable ( "UNO_BOOTSTRAP_LOG_PROFILER_OPTIONS" , LogProfilerOptions ) ;
617
- }
618
-
619
- config . AppendLine ( "export { config };" ) ;
620
-
621
- w . Write ( config . ToString ( ) ) ;
622
-
623
- TaskItem indexMetadata = new (
624
- unoConfigJsPath , new Dictionary < string , string >
625
- {
626
- [ "CopyToOutputDirectory" ] = "PreserveNewest" ,
627
- [ "ContentRoot" ] = _intermediateAssetsPath ,
628
- [ "Link" ] = $ "wwwroot/{ PackageAssetsFolder } /" + Path . GetFileName ( unoConfigJsPath ) ,
629
- } ) ;
630
-
631
- StaticWebContent = StaticWebContent . Concat ( [ indexMetadata ] ) . ToArray ( ) ;
632
- }
537
+ GenerateConfigFile ( "uno-config-script.js" , isModule : false ) ;
633
538
}
634
539
635
-
636
-
637
- private void GenerateConfigScript ( )
540
+ private void GenerateConfigFile ( string fileName , bool isModule )
638
541
{
639
- var unoConfigJsPath = Path . Combine ( _intermediateAssetsPath , "uno-config-script.js" ) ;
542
+ var self = isModule ? "" : "self." ;
543
+
544
+ var unoConfigJsPath = Path . Combine ( _intermediateAssetsPath , fileName ) ;
640
545
641
546
using ( var w = new StreamWriter ( unoConfigJsPath , false , _utf8Encoding ) )
642
547
{
@@ -657,7 +562,7 @@ private void GenerateConfigScript()
657
562
. Select ( f => f . GetMetadata ( "Link" )
658
563
. Replace ( "\\ " , "/" )
659
564
. Replace ( "wwwroot/" , "" ) )
660
- . Concat ( [ $ "uno-config-script.js" , "_framework/blazor.boot.json" , "." ] ) ;
565
+ . Concat ( [ fileName , "_framework/blazor.boot.json" , "." ] ) ;
661
566
662
567
var offlineFiles = enablePWA ? string . Join ( ", " , sanitizedOfflineFiles . Select ( f => $ "\" { WebAppBasePath } { f } \" ") ) : "" ;
663
568
@@ -667,27 +572,36 @@ private void GenerateConfigScript()
667
572
668
573
var runtimeOptionsSet = string . Join ( "," , ( RuntimeOptions ? . Split ( ' ' ) ?? [ ] ) . Select ( f => $ "\' { f } \' ") ) ;
669
574
670
- config . AppendLine ( $ "self.config = {{}};") ;
671
- config . AppendLine ( $ "self.config.uno_remote_managedpath = \" _framework\" ;") ;
672
- config . AppendLine ( $ "self.config.uno_app_base = \" { WebAppBasePath } { PackageAssetsFolder } \" ;") ;
673
- config . AppendLine ( $ "self.config.uno_dependencies = [{ dependencies } ];") ;
674
- config . AppendLine ( $ "self.config.uno_runtime_options = [{ runtimeOptionsSet } ];") ;
675
- config . AppendLine ( $ "self.config.enable_pwa = { enablePWA . ToString ( ) . ToLowerInvariant ( ) } ;") ;
676
- config . AppendLine ( $ "self.config.offline_files = ['{ WebAppBasePath } ', { offlineFiles } ];") ;
677
- config . AppendLine ( $ "self.config.uno_shell_mode = \" { _shellMode } \" ;") ;
678
- config . AppendLine ( $ "self.config.uno_debugging_enabled = { ( ! Optimize ) . ToString ( ) . ToLowerInvariant ( ) } ;") ;
679
- config . AppendLine ( $ "self.config.uno_enable_tracing = { EnableTracing . ToString ( ) . ToLowerInvariant ( ) } ;") ;
680
- config . AppendLine ( $ "self.config.uno_load_all_satellite_resources = { LoadAllSatelliteResources . ToString ( ) . ToLowerInvariant ( ) } ;") ;
681
- config . AppendLine ( $ "self.config.emcc_exported_runtime_methods = [{ emccExportedRuntimeMethodsParams } ];") ;
575
+
576
+ if ( isModule )
577
+ {
578
+ config . AppendLine ( $ "let config = {{}};") ;
579
+ }
580
+ else
581
+ {
582
+ config . AppendLine ( $ "{ self } config = {{}};") ;
583
+ }
584
+
585
+ config . AppendLine ( $ "{ self } config.uno_remote_managedpath = \" _framework\" ;") ;
586
+ config . AppendLine ( $ "{ self } config.uno_app_base = \" { WebAppBasePath } { PackageAssetsFolder } \" ;") ;
587
+ config . AppendLine ( $ "{ self } config.uno_dependencies = [{ dependencies } ];") ;
588
+ config . AppendLine ( $ "{ self } config.uno_runtime_options = [{ runtimeOptionsSet } ];") ;
589
+ config . AppendLine ( $ "{ self } config.enable_pwa = { enablePWA . ToString ( ) . ToLowerInvariant ( ) } ;") ;
590
+ config . AppendLine ( $ "{ self } config.offline_files = ['{ WebAppBasePath } ', { offlineFiles } ];") ;
591
+ config . AppendLine ( $ "{ self } config.uno_shell_mode = \" { _shellMode } \" ;") ;
592
+ config . AppendLine ( $ "{ self } config.uno_debugging_enabled = { ( ! Optimize ) . ToString ( ) . ToLowerInvariant ( ) } ;") ;
593
+ config . AppendLine ( $ "{ self } config.uno_enable_tracing = { EnableTracing . ToString ( ) . ToLowerInvariant ( ) } ;") ;
594
+ config . AppendLine ( $ "{ self } config.uno_load_all_satellite_resources = { LoadAllSatelliteResources . ToString ( ) . ToLowerInvariant ( ) } ;") ;
595
+ config . AppendLine ( $ "{ self } config.emcc_exported_runtime_methods = [{ emccExportedRuntimeMethodsParams } ];") ;
682
596
683
597
if ( GenerateAOTProfile )
684
598
{
685
- config . AppendLine ( $ "self. config.generate_aot_profile = true;") ;
599
+ config . AppendLine ( $ "{ self } config.generate_aot_profile = true;") ;
686
600
}
687
601
688
- config . AppendLine ( $ "self. config.environmentVariables = self. config.environmentVariables || {{}};") ;
602
+ config . AppendLine ( $ "{ self } config.environmentVariables = { self } config.environmentVariables || {{}};") ;
689
603
690
- void AddEnvironmentVariable ( string name , string value ) => config . AppendLine ( $ "self. config.environmentVariables[\" { name } \" ] = \" { value } \" ;") ;
604
+ void AddEnvironmentVariable ( string name , string value ) => config . AppendLine ( $ "{ self } config.environmentVariables[\" { name } \" ] = \" { value } \" ;") ;
691
605
692
606
if ( MonoEnvironment != null )
693
607
{
@@ -719,6 +633,11 @@ private void GenerateConfigScript()
719
633
AddEnvironmentVariable ( "UNO_BOOTSTRAP_LOG_PROFILER_OPTIONS" , LogProfilerOptions ) ;
720
634
}
721
635
636
+ if ( isModule )
637
+ {
638
+ config . AppendLine ( "export { config };" ) ;
639
+ }
640
+
722
641
w . Write ( config . ToString ( ) ) ;
723
642
724
643
TaskItem indexMetadata = new (
0 commit comments