Mumrich.SpaDevMiddleware
1.4.0-PullRequest0003.10
See the version list below for details.
dotnet add package Mumrich.SpaDevMiddleware --version 1.4.0-PullRequest0003.10
NuGet\Install-Package Mumrich.SpaDevMiddleware -Version 1.4.0-PullRequest0003.10
<PackageReference Include="Mumrich.SpaDevMiddleware" Version="1.4.0-PullRequest0003.10" />
paket add Mumrich.SpaDevMiddleware --version 1.4.0-PullRequest0003.10
#r "nuget: Mumrich.SpaDevMiddleware, 1.4.0-PullRequest0003.10"
// Install Mumrich.SpaDevMiddleware as a Cake Addin #addin nuget:?package=Mumrich.SpaDevMiddleware&version=1.4.0-PullRequest0003.10&prerelease // Install Mumrich.SpaDevMiddleware as a Cake Tool #tool nuget:?package=Mumrich.SpaDevMiddleware&version=1.4.0-PullRequest0003.10&prerelease
Mumrich.SpaDevMiddleware
A .NET Middleware for ASP.NET Core that automatically integrates (multiple) Single-Page-Apps in a .NET-Webhost.
- Automatic node-package install (
npm
/yarn
/pnpm
) - SPAs are automatically built upon (
dotnet publish
triggers thebuild
-script inpackage.json
) - Automatic path-mapping for the SPA by aid of the superb 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.Modify the
csproj
-file by adding the followingItemGroup
and adjust the values accordingly:<ItemGroup> <SpaRoot Include="MyApp\"> <InstallCommand>npm install</InstallCommand> <BuildCommand>npm run build</BuildCommand> <BuildOutputPath>MyApp\dist\**</BuildOutputPath> </SpaRoot> </ItemGroup>
Implement the
ISpaDevServerSettings
-interface:public class AppSettings : ISpaDevServerSettings { public Dictionary<string, SpaSettings> SinglePageApps { get; set; } = new(); public string SpaRootPath { get; set; } = Directory.GetCurrentDirectory(); public bool UseParentObserverServiceOnWindows { get; set; } = true; }
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": "Npm", } } }
Register Services and setup app e.g.:
using Mumrich.SpaDevMiddleware.Extensions; var builder = WebApplication.CreateBuilder(args); var appSettings = builder.Configuration.Get<AppSettings>(); builder.RegisterSinglePageAppDevMiddleware(appSettings); var app = builder.Build(); 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:// https://vitejs.dev/config/ export default defineConfig({ plugins: [vue()], server: { host: true, port: 3000, strictPort: true, }, });
Run the app (
dotnet run
), navigate to the .NET-Web-host-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 | net7.0 is compatible. 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 is compatible. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net7.0
- Akka.Hosting (>= 1.5.13)
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
- Mumrich.AkkaExt (>= 1.2.1)
- Mumrich.HelpersAndExtensions (>= 1.0.0)
- Mumrich.SpaDevMiddleware.Domain (>= 1.4.0-PullRequest0003.10)
- Mumrich.SpaDevMiddleware.MsBuild (>= 1.4.0-PullRequest0003.10)
- Yarp.ReverseProxy (>= 2.1.0)
-
net8.0
- Akka.Hosting (>= 1.5.13)
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
- Mumrich.AkkaExt (>= 1.2.1)
- Mumrich.HelpersAndExtensions (>= 1.0.0)
- Mumrich.SpaDevMiddleware.Domain (>= 1.4.0-PullRequest0003.10)
- Mumrich.SpaDevMiddleware.MsBuild (>= 1.4.0-PullRequest0003.10)
- Yarp.ReverseProxy (>= 2.1.0)
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 | 168 | 5/1/2024 |
1.4.1-PullRequest0004.4 | 70 | 4/30/2024 |
1.4.1-PullRequest0004.3 | 65 | 4/30/2024 |
1.4.1-PullRequest0004.2 | 63 | 4/19/2024 |
1.4.0 | 442 | 12/12/2023 |
1.4.0-PullRequest0003.11 | 77 | 12/12/2023 |
1.4.0-PullRequest0003.10 | 71 | 12/12/2023 |
1.4.0-PullRequest0003.9 | 63 | 12/12/2023 |
1.4.0-PullRequest0003.8 | 76 | 12/12/2023 |
1.3.5 | 2,873 | 8/23/2023 |
1.3.5-PullRequest0002.1 | 80 | 8/23/2023 |
1.3.4 | 149 | 8/23/2023 |
1.3.3 | 227 | 3/24/2023 |
1.3.2 | 283 | 3/24/2023 |
1.3.1 | 214 | 3/24/2023 |
1.3.0-alpha.10 | 128 | 9/1/2022 |
1.3.0-alpha.6 | 118 | 9/1/2022 |
1.3.0-alpha.5 | 114 | 9/1/2022 |
1.2.1 | 326 | 1/12/2023 |
1.2.1-PullRequest0012.21 | 120 | 1/12/2023 |
1.2.0 | 2,088 | 10/5/2022 |
1.2.0-PullRequest0010.13 | 100 | 10/5/2022 |
1.2.0-PullRequest0009.13 | 93 | 10/5/2022 |
1.2.0-PullRequest0009.2 | 101 | 10/5/2022 |
1.1.2 | 477 | 9/28/2022 |
1.1.2-PullRequest0008.6 | 142 | 9/28/2022 |
1.1.2-PullRequest0008.5 | 131 | 9/28/2022 |
1.1.1 | 473 | 9/28/2022 |
1.1.0 | 473 | 9/28/2022 |
1.1.0-PullRequest0007.8 | 164 | 9/28/2022 |
1.0.5-PullRequest0007.7 | 177 | 9/28/2022 |
1.0.5-PullRequest0007.6 | 167 | 9/28/2022 |
1.0.5-PullRequest0006.1 | 120 | 7/14/2022 |
1.0.4 | 469 | 7/14/2022 |
1.0.4-PullRequest0006.3 | 122 | 7/14/2022 |
1.0.4-PullRequest0005.1 | 135 | 5/6/2022 |
1.0.3 | 459 | 5/6/2022 |
1.0.2 | 533 | 4/19/2022 |
1.0.0 | 451 | 4/19/2022 |
0.1.62 | 463 | 4/19/2022 |
0.1.62-PullRequest0004.3 | 133 | 4/19/2022 |
0.1.61 | 439 | 4/10/2022 |
0.1.60 | 437 | 4/10/2022 |
0.1.59 | 461 | 3/2/2022 |
0.1.54 | 458 | 3/1/2022 |
0.1.53 | 457 | 3/1/2022 |
0.1.52 | 459 | 3/1/2022 |
0.1.51 | 452 | 3/1/2022 |
0.1.50 | 451 | 3/1/2022 |
0.1.49 | 444 | 3/1/2022 |
0.1.48 | 455 | 3/1/2022 |
0.1.48-PullRequest0003.8 | 132 | 3/1/2022 |
0.1.47 | 470 | 2/24/2022 |
0.1.47-PullRequest0002.6 | 150 | 2/24/2022 |
0.1.46 | 460 | 2/23/2022 |
0.1.40-experimental.27 | 154 | 2/23/2022 |