|
105 | 105 | </PropertyGroup> |
106 | 106 |
|
107 | 107 | <Target Name="GenerateCloudflareIndex" |
| 108 | + AfterTargets="Publish" |
108 | 109 | BeforeTargets="PrepareCloudflareOutput" |
109 | 110 | Condition="'$(RuntimeIdentifier)' == 'browser-wasm'"> |
110 | 111 | <MakeDir Directories="$(CloudflareIndexGeneratedDir)" /> |
111 | 112 |
|
| 113 | + <ItemGroup> |
| 114 | + <_DiscoveredWasmLibraryScripts Include="$(PublishDir)*.wasmlib.js" /> |
| 115 | + </ItemGroup> |
| 116 | + |
| 117 | + <Message Text="Discovered WASM library scripts: @(_DiscoveredWasmLibraryScripts)" Importance="normal" |
| 118 | + Condition="'@(_DiscoveredWasmLibraryScripts)' != ''" /> |
| 119 | + |
| 120 | + <!-- |
| 121 | + Build library import statements using batching. |
| 122 | + The module name is extracted from the filename by removing .wasmlib suffix. |
| 123 | + The variable name uses underscore instead of dots for valid JS identifiers. |
| 124 | + Note: Using placeholders for special characters to avoid MSBuild parsing issues. |
| 125 | + --> |
| 126 | + <ItemGroup> |
| 127 | + <_LibraryImportLines Include="import __STAR__ as _lib_$([System.String]::Copy('%(_DiscoveredWasmLibraryScripts.Filename)').Replace('.wasmlib', '').Replace('.', '_').Replace('-', '_')) from __QUOTE__./%(_DiscoveredWasmLibraryScripts.Filename)%(_DiscoveredWasmLibraryScripts.Extension)__QUOTE____SEMI__" |
| 128 | + Condition="'@(_DiscoveredWasmLibraryScripts)' != ''" /> |
| 129 | + <_LibraryModuleLines Include=" __QUOTE__$([System.String]::Copy('%(_DiscoveredWasmLibraryScripts.Filename)').Replace('.wasmlib', ''))__QUOTE__: _lib_$([System.String]::Copy('%(_DiscoveredWasmLibraryScripts.Filename)').Replace('.wasmlib', '').Replace('.', '_').Replace('-', '_'))," |
| 130 | + Condition="'@(_DiscoveredWasmLibraryScripts)' != ''" /> |
| 131 | + </ItemGroup> |
| 132 | + |
| 133 | + <PropertyGroup> |
| 134 | + <_LibraryImportStatements>@(_LibraryImportLines, '%0a')</_LibraryImportStatements> |
| 135 | + <_LibraryImportStatements>$(_LibraryImportStatements.Replace('__STAR__', '*'))</_LibraryImportStatements> |
| 136 | + <_LibraryImportStatements>$(_LibraryImportStatements.Replace('__QUOTE__', "'"))</_LibraryImportStatements> |
| 137 | + <_LibraryImportStatements>$(_LibraryImportStatements.Replace('__SEMI__', ';'))</_LibraryImportStatements> |
| 138 | + <_LibraryModuleRegistrations>@(_LibraryModuleLines, '%0a')</_LibraryModuleRegistrations> |
| 139 | + <_LibraryModuleRegistrations>$(_LibraryModuleRegistrations.Replace('__QUOTE__', "'"))</_LibraryModuleRegistrations> |
| 140 | + </PropertyGroup> |
| 141 | + |
112 | 142 | <PropertyGroup> |
113 | 143 | <_CloudflareIndexTemplate>$([System.IO.File]::ReadAllText('$(CloudflareIndexTemplatePath)'))</_CloudflareIndexTemplate> |
114 | 144 | <_CloudflareIndexContent>$(_CloudflareIndexTemplate.Replace('__MAIN_ASSEMBLY__', '$(AssemblyName)'))</_CloudflareIndexContent> |
| 145 | + <_CloudflareIndexContent>$(_CloudflareIndexContent.Replace('// __LIBRARY_IMPORTS__', '$(_LibraryImportStatements)'))</_CloudflareIndexContent> |
| 146 | + <_CloudflareIndexContent>$(_CloudflareIndexContent.Replace(' // __LIBRARY_MODULES__', '$(_LibraryModuleRegistrations)'))</_CloudflareIndexContent> |
115 | 147 | </PropertyGroup> |
116 | 148 |
|
117 | 149 | <WriteLinesToFile File="$(CloudflareIndexGeneratedPath)" |
|
151 | 183 |
|
152 | 184 | <Target Name="PrepareCloudflareOutput" |
153 | 185 | AfterTargets="Publish" |
| 186 | + DependsOnTargets="GenerateCloudflareIndex;GenerateCloudflareWrangler" |
154 | 187 | Condition="'$(RuntimeIdentifier)' == 'browser-wasm'"> |
155 | 188 | <MakeDir Directories="$(CloudflareOutputPath)" /> |
156 | 189 |
|
|
184 | 217 | SkipUnchangedFiles="true" |
185 | 218 | Condition="Exists('$(PublishDir)dotnet.runtime.js')" /> |
186 | 219 |
|
| 220 | + <!-- Copy library JavaScript files to cloudflare output (discovered from publish directory) --> |
| 221 | + <ItemGroup> |
| 222 | + <_WasmLibScriptsToCopy Include="$(PublishDir)*.wasmlib.js" /> |
| 223 | + </ItemGroup> |
| 224 | + |
| 225 | + <Copy SourceFiles="@(_WasmLibScriptsToCopy)" |
| 226 | + DestinationFolder="$(CloudflareOutputPath)" |
| 227 | + SkipUnchangedFiles="true" |
| 228 | + Condition="'@(_WasmLibScriptsToCopy)' != ''" /> |
| 229 | + |
187 | 230 | <Copy SourceFiles="$(PublishDir)$(AssemblyName).wasm" |
188 | 231 | DestinationFolder="$(CloudflareOutputPath)" |
189 | 232 | SkipUnchangedFiles="true" |
|
0 commit comments