Mumrich.SpaDevMiddleware
1.2.0-PullRequest0010.13
See the version list below for details.
dotnet add package Mumrich.SpaDevMiddleware --version 1.2.0-PullRequest0010.13
NuGet\Install-Package Mumrich.SpaDevMiddleware -Version 1.2.0-PullRequest0010.13
<PackageReference Include="Mumrich.SpaDevMiddleware" Version="1.2.0-PullRequest0010.13" />
paket add Mumrich.SpaDevMiddleware --version 1.2.0-PullRequest0010.13
#r "nuget: Mumrich.SpaDevMiddleware, 1.2.0-PullRequest0010.13"
// Install Mumrich.SpaDevMiddleware as a Cake Addin #addin nuget:?package=Mumrich.SpaDevMiddleware&version=1.2.0-PullRequest0010.13&prerelease // Install Mumrich.SpaDevMiddleware as a Cake Tool #tool nuget:?package=Mumrich.SpaDevMiddleware&version=1.2.0-PullRequest0010.13&prerelease
Mumrich.SpaDevMiddleware
A .NET Middleware for ASP.NET Core 6 that automatically integrates (multiple) Single-Page-Apps in a .NET-Webhost.
- Automatic node-package install (
npm
/yarn
/pnpm
) - SPAs are automatically built uppon (
dotnet publish
triggers thebuild
-script inpackage.json
) - Automatic path-mapping for the SPA by aid of the supperb YARP
- SPA Hot-Reloading supported
- Custom-ENV-Variables can be passed to the Node-Instance via
appsettings.json
- Usage of MSBUILD-Variables supported
Usage
Install the
Mumrich.SpaDevMiddleware
Nuget-Package into your Web-Project (.NET 6)Implement the
ISpaDevServerSettings
-interface:public class AppSettings : ISpaDevServerSettings { public Dictionary<string, SpaSettings> SinglePageApps { get; set; } = new(); }
Create the MSBuild-Item-Group in the
csproj
-File for node-package install and dotnet-publish to work "out of the box":<ItemGroup> <SpaRoot Include="app1\" /> <SpaRoot Include="app2\" /> </ItemGroup>
Extend
appsettings.json
with a SPA-Config e.g.:{ "Logging": { "LogLevel": { "Default": "Information", "Microsoft.AspNetCore": "Warning" } }, "AllowedHosts": "*", "SinglePageApps": { "/": { "DevServerAddress": "http://localhost:3000/", "SpaRootPath": "app1", "NodePackageManager": "Yarn", "NodeStartScript": "dev", "Regex": "dev server running at:", "Bundler": "ViteJs", "Environment": { "HMR_PORT": "%ASPNETCORE_HTTPS_PORT%", "HMR_PROTOCOL": "wss" } }, "/admin": { "DevServerAddress": "http://localhost:9000/", "SpaRootPath": "app2", "NodePackageManager": "Yarn", "NodeStartScript": "dev", "Regex": "Opening default browser", "Bundler": "ViteJs" } } }
Register Services and setup app e.g.:
using Mumrich.SpaDevMiddleware.Extensions; var builder = WebApplication.CreateBuilder(args); var appSettings = builder.Configuration.Get<AppSettings>(); builder.Services.AddControllersWithViews(); builder.Services.AddCors(); builder.RegisterSinglePageAppDevMiddleware(appSettings); var app = builder.Build(); app.UseStaticFiles(); app.UseHttpsRedirection(); app.UseRouting(); app.UseCors(); app.MapControllers(); app.MapSinglePageApps(appSettings); app.Run();
When using hot-reloading, adapt your SPA-bundling-setup accordingly to accept the .NET-Webhost-Proxy on the correct Port. Custom-ENV-Variables can be passed via
appsettings.json
- e.g for vite.config.ts:const protocol = process.env.HMR_PROTOCOL ?? "ws"; const port = Number(process.env.HMR_PORT) ?? 3000; // https://vitejs.dev/config/ export default defineConfig({ plugins: [vue()], server: { port: 3000, strictPort: true, hmr: { protocol, port, }, }, });
Run the app (
dotnet run
), navigate to the .NET-Webhost-Url and enjoy 👌!
Troubleshooting
- See the working Example in the
WebSpaVue
-folder.
Credits
- Thx to aspnetcore-vueclimiddleware for providing insights how to handle console-output.
- Thx to AspNetCore.SpaYarp for providing idea and insights to use YARP.
- Thx to YARP for providing such a wonderfull tool.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- Akka.Hosting (>= 0.4.2)
- Microsoft.Extensions.Hosting.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 6.0.0)
- Mumrich.AkkaExt (>= 1.2.0-PullRequest0010.13)
- Mumrich.HelpersAndExtensions (>= 1.0.0)
- Yarp.ReverseProxy (>= 1.1.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.4.1 | 156 | 5/1/2024 |
1.4.1-PullRequest0004.4 | 67 | 4/30/2024 |
1.4.1-PullRequest0004.3 | 62 | 4/30/2024 |
1.4.1-PullRequest0004.2 | 60 | 4/19/2024 |
1.4.0 | 438 | 12/12/2023 |
1.4.0-PullRequest0003.11 | 74 | 12/12/2023 |
1.4.0-PullRequest0003.10 | 68 | 12/12/2023 |
1.4.0-PullRequest0003.9 | 60 | 12/12/2023 |
1.4.0-PullRequest0003.8 | 73 | 12/12/2023 |
1.3.5 | 2,382 | 8/23/2023 |
1.3.5-PullRequest0002.1 | 77 | 8/23/2023 |
1.3.4 | 146 | 8/23/2023 |
1.3.3 | 219 | 3/24/2023 |
1.3.2 | 273 | 3/24/2023 |
1.3.1 | 207 | 3/24/2023 |
1.3.0-alpha.10 | 119 | 9/1/2022 |
1.3.0-alpha.6 | 110 | 9/1/2022 |
1.3.0-alpha.5 | 106 | 9/1/2022 |
1.2.1 | 315 | 1/12/2023 |
1.2.1-PullRequest0012.21 | 111 | 1/12/2023 |
1.2.0 | 1,964 | 10/5/2022 |
1.2.0-PullRequest0010.13 | 91 | 10/5/2022 |
1.2.0-PullRequest0009.13 | 84 | 10/5/2022 |
1.2.0-PullRequest0009.2 | 92 | 10/5/2022 |
1.1.2 | 466 | 9/28/2022 |
1.1.2-PullRequest0008.6 | 133 | 9/28/2022 |
1.1.2-PullRequest0008.5 | 123 | 9/28/2022 |
1.1.1 | 462 | 9/28/2022 |
1.1.0 | 462 | 9/28/2022 |
1.1.0-PullRequest0007.8 | 155 | 9/28/2022 |
1.0.5-PullRequest0007.7 | 167 | 9/28/2022 |
1.0.5-PullRequest0007.6 | 159 | 9/28/2022 |
1.0.5-PullRequest0006.1 | 111 | 7/14/2022 |
1.0.4 | 459 | 7/14/2022 |
1.0.4-PullRequest0006.3 | 113 | 7/14/2022 |
1.0.4-PullRequest0005.1 | 126 | 5/6/2022 |
1.0.3 | 449 | 5/6/2022 |
1.0.2 | 521 | 4/19/2022 |
1.0.0 | 439 | 4/19/2022 |
0.1.62 | 452 | 4/19/2022 |
0.1.62-PullRequest0004.3 | 123 | 4/19/2022 |
0.1.61 | 428 | 4/10/2022 |
0.1.60 | 426 | 4/10/2022 |
0.1.59 | 448 | 3/2/2022 |
0.1.54 | 444 | 3/1/2022 |
0.1.53 | 443 | 3/1/2022 |
0.1.52 | 445 | 3/1/2022 |
0.1.51 | 438 | 3/1/2022 |
0.1.50 | 438 | 3/1/2022 |
0.1.49 | 431 | 3/1/2022 |
0.1.48 | 442 | 3/1/2022 |
0.1.48-PullRequest0003.8 | 121 | 3/1/2022 |
0.1.47 | 457 | 2/24/2022 |
0.1.47-PullRequest0002.6 | 138 | 2/24/2022 |
0.1.46 | 447 | 2/23/2022 |
0.1.40-experimental.27 | 141 | 2/23/2022 |