Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Blazor WebAssembly Standalone launchable by default in Boilerplate (#8745) #8756

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/admin-sample.cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
- name: Publish adminpanel blazor wasm standalone
run: |
sed -i 's/adminpanel.bitplatform.dev/adminpanel-api.bitplatform.dev/g' AdminPanel/src/Client/AdminPanel.Client.Web/wwwroot/index.html
dotnet publish AdminPanel/src/Client/AdminPanel.Client.Web/AdminPanel.Client.Web.csproj -c Release -p:BlazorWebAssemblyStandalone=true -o ${{env.DOTNET_ROOT}}/static
dotnet publish AdminPanel/src/Client/AdminPanel.Client.Web/AdminPanel.Client.Web.csproj -c Release -p:PwaEnabled=true -o ${{env.DOTNET_ROOT}}/static

- name: Upload static artifact
uses: actions/upload-artifact@v4
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/bit.full.ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ jobs:
- name: Test sample configuration 1
run: |
dotnet new bit-bp --name TestProject --database Cosmos --filesStorage AzureBlobStorage --api Integrated --captcha reCaptcha --pipeline Azure --sample Admin --offlineDb true --windows true --appInsights true --appCenter true --signalr true
dotnet build TestProject/TestProject.sln -p:MultilingualEnabled=true -p:PWA=true -p:BlazorWebAssemblyStandalone=true -p:Environment=Staging
dotnet build TestProject/TestProject.sln -p:MultilingualEnabled=true -p:PwaEnabled=true -p:Environment=Staging

- name: Test sample configuration 2
run: |
dotnet new bit-bp --name TestProject2 --database Other --filesStorage Other --api Standalone --captcha None --pipeline None --sample None --offlineDb false --windows false --appInsights false --appCenter false --signalr false
dotnet build TestProject2/TestProject2.sln -p:MultilingualEnabled=false -p:PWA=false -p:BlazorWebAssemblyStandalone=false -p:Environment=Development
dotnet build TestProject2/TestProject2.sln -p:MultilingualEnabled=false -p:PwaEnabled=false -p:Environment=Development

- name: Run BeforeBuildTasks
continue-on-error: true # Error MSB4057, not all csproj files have BeforeBuildTasks target.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<WasmEnableSIMD>false</WasmEnableSIMD>
<ServiceWorkerAssetsManifest Condition=" '$(PwaEnabled)' == 'true' ">service-worker-assets.js</ServiceWorkerAssetsManifest>
<BlazorCacheBootResources Condition=" '$(PwaEnabled)' == 'true' ">false</BlazorCacheBootResources>
<NoDefaultLaunchSettingsFile>true</NoDefaultLaunchSettingsFile>
<StaticWebAssetProjectMode>Default</StaticWebAssetProjectMode>
<!--/+:msbuild-conditional:noEmit -->
<WasmStripILAfterAOT Condition=" '$(offlineDb)' == 'false'">true</WasmStripILAfterAOT>
Expand All @@ -21,12 +20,7 @@
</PropertyGroup>

<ItemGroup Condition=" '$(PwaEnabled)' == 'true' ">
<ServiceWorker Include="wwwroot\service-worker.js" PublishedContent="wwwroot\service-worker.js" />
</ItemGroup>

<ItemGroup Condition=" '$(BlazorWebAssemblyStandalone)' == 'false' ">
<Content Remove="wwwroot\index.html" />
<None Remove="Properties\launchSettings.json" />
<ServiceWorker Include="wwwroot\service-worker.js" PublishedContent="wwwroot\service-worker.published.js" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
//-:cnd:noEmit
using System.Web;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Bit.Butil;
#if BlazorWebAssemblyStandalone
using Microsoft.AspNetCore.Components.Web;
#endif

namespace Boilerplate.Client.Web;

Expand All @@ -17,10 +15,13 @@ public static async Task Main(string[] args)

AppEnvironment.Set(builder.HostEnvironment.Environment);

#if BlazorWebAssemblyStandalone
builder.RootComponents.Add<Routes>("#app-container");
builder.RootComponents.Add<HeadOutlet>("head::after");
#endif
if (Environment.GetEnvironmentVariable("__BLAZOR_WEBASSEMBLY_WAIT_FOR_ROOT_COMPONENTS") != "true")
{
// By default, App.razor adds Routes and HeadOutlet.
// The following is only required for blazor webassembly standalone.
builder.RootComponents.Add<Routes>("#app-container");
builder.RootComponents.Add<HeadOutlet>("head::after");
}

//+:cnd:noEmit
//#if (appInsights == true)
Expand Down Expand Up @@ -51,18 +52,6 @@ public static async Task Main(string[] args)
host.Services.GetRequiredService<CultureInfoManager>().SetCurrentCulture(culture);
}

try
{
await host.RunAsync();
}
catch (JSException exp) when (exp.Message is "Error: Could not find any element matching selector '#app-container'.")
{
#if BlazorWebAssemblyStandalone
await System.Console.Error.WriteLineAsync("Either run/publish Client.Web project or set BlazorWebAssemblyStandalone to false.");
#else
throw;
#endif
}

await host.RunAsync();
}
}
Original file line number Diff line number Diff line change
@@ -1,42 +1,4 @@
// bit version: 8.11.1-pre-02
// https://github.com/bitfoundation/bitplatform/tree/develop/src/Bswup

self.assetsInclude = [];
self.assetsExclude = [
/bit\.blazorui\.fluent\.css$/,
/bit\.blazorui\.fluent-dark\.css$/,
/bit\.blazorui\.fluent-light\.css$/
];
self.externalAssets = [
{
"url": "/"
},
{
url: "_framework/blazor.web.js"
},
{
"url": "Boilerplate.Server.Web.styles.css"
}
];

self.serverHandledUrls = [
/\/api\//,
/\/odata\//,
/\/jobs\//,
/\/core\//,
/\/signalr\//,
/\/healthchecks-ui/,
/\/healthz/,
/\/swagger/,
/\/signin-/,
/\/.well-known/,
/\/sitemap.xml/,
];

self.defaultUrl = "/";
self.caseInsensitiveUrl = true;
self.noPrerenderQuery = 'no-prerender=true';
self.isPassive = self.disablePassiveFirstBoot = true;
self.errorTolerance = 'lax';

self.importScripts('_content/Bit.Bswup/bit-bswup.sw.js');
// In development, always fetch from the network and do not enable offline support.
// This is because caching would make development more difficult (changes would not
// be reflected on the first load after each change).
self.addEventListener('fetch', () => { });
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// bit version: 8.11.1-pre-02
// https://github.com/bitfoundation/bitplatform/tree/develop/src/Bswup

self.assetsInclude = [];
self.assetsExclude = [
/bit\.blazorui\.fluent\.css$/,
/bit\.blazorui\.fluent-dark\.css$/,
/bit\.blazorui\.fluent-light\.css$/
];
self.externalAssets = [
{
"url": "/"
},
{
url: "_framework/blazor.web.js"
},
{
"url": "Boilerplate.Server.Web.styles.css"
}
];

self.serverHandledUrls = [
/\/api\//,
/\/odata\//,
/\/jobs\//,
/\/core\//,
/\/signalr\//,
/\/healthchecks-ui/,
/\/healthz/,
/\/swagger/,
/\/signin-/,
/\/.well-known/,
/\/sitemap.xml/,
];

self.defaultUrl = "/";
self.caseInsensitiveUrl = true;
self.noPrerenderQuery = 'no-prerender=true';
self.isPassive = self.disablePassiveFirstBoot = true;
self.errorTolerance = 'lax';

self.importScripts('_content/Bit.Bswup/bit-bswup.sw.js');
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@
<NeutralLanguage>en-US</NeutralLanguage>
<MultilingualEnabled>true</MultilingualEnabled>
<PwaEnabled>false</PwaEnabled>
<BlazorWebAssemblyStandalone>false</BlazorWebAssemblyStandalone>
<!-- By enabling the BlazorWebAssemblyStandalone option, you gain the ability to
deploy your Client.Web project on platforms such as GitHub/Cloudflare Pages and Azure Static Web Apps. -->

<PwaEnabled Condition=" '$(BlazorWebAssemblyStandalone)' == 'true' ">true</PwaEnabled>

<!-- See Boilerplate.Shared.AppEnvironment for more info. -->
<Environment Condition="'$(Environment)' == '' AND '$(Configuration)' == 'Debug'">Development</Environment>
Expand All @@ -37,15 +32,14 @@
<DefineConstants Condition=" $(TargetFramework.Contains('-windows')) ">$(DefineConstants);Windows</DefineConstants>
<DefineConstants Condition=" $(TargetFramework.Contains('-mac')) ">$(DefineConstants);Mac</DefineConstants>
<DefineConstants Condition=" '$(MultilingualEnabled)' == 'true' ">$(DefineConstants);MultilingualEnabled</DefineConstants>
<DefineConstants Condition=" '$(BlazorWebAssemblyStandalone)' == 'true' ">$(DefineConstants);BlazorWebAssemblyStandalone</DefineConstants>
<DefineConstants Condition=" '$(PwaEnabled)' == 'true' ">$(DefineConstants);PwaEnabled</DefineConstants>
<DefineConstants>$(DefineConstants);$(Environment)</DefineConstants>
</PropertyGroup>
<!--/+:msbuild-conditional:noEmit -->

<ItemGroup>
<PackageReference Include="Bit.CodeAnalyzers"/>
<PackageReference Include="Bit.SourceGenerators" />
<PackageReference Include="Bit.CodeAnalyzers" PrivateAssets="all" />
<PackageReference Include="Bit.SourceGenerators" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading