Mumrich.SpaDevMiddleware 1.5.1

dotnet add package Mumrich.SpaDevMiddleware --version 1.5.1
                    
NuGet\Install-Package Mumrich.SpaDevMiddleware -Version 1.5.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Mumrich.SpaDevMiddleware" Version="1.5.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Mumrich.SpaDevMiddleware" Version="1.5.1" />
                    
Directory.Packages.props
<PackageReference Include="Mumrich.SpaDevMiddleware" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Mumrich.SpaDevMiddleware --version 1.5.1
                    
#r "nuget: Mumrich.SpaDevMiddleware, 1.5.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Mumrich.SpaDevMiddleware@1.5.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Mumrich.SpaDevMiddleware&version=1.5.1
                    
Install as a Cake Addin
#tool nuget:?package=Mumrich.SpaDevMiddleware&version=1.5.1
                    
Install as a Cake Tool

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 the build-script in package.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

  1. Install the Mumrich.SpaDevMiddleware Nuget-Package into your Web-Project.

  2. Modify the csproj-file by adding the following ItemGroup and adjust the values accordingly:

    <ItemGroup>
      <SpaRoot Include="MyApp\">
        <InstallCommand>npm install</InstallCommand>
        <BuildCommand>npm run build</BuildCommand>
        <BuildOutputPath>MyApp\dist\**</BuildOutputPath>
      </SpaRoot>
    </ItemGroup>
    
  3. Implement the ISpaDevServerSettings-interface:

    public class AppSettings : ISpaDevServerSettings
    {
      public Dictionary<string, SpaSettings> SinglePageApps { get; set; } = new();
      public string SpaRootPath { get; set; } = Directory.GetCurrentDirectory();
    }
    
  4. Extend appsettings.json with a SPA-Config e.g.:

    {
      "Logging": {
        "LogLevel": {
          "Default": "Information",
          "Microsoft.AspNetCore": "Warning"
        }
      },
      "AllowedHosts": "*",
      "SinglePageApps": {
        "/": {
          "DevServerAddress": "http://localhost:3000/",
          "SpaRootPath": "MyApp",
          "NodePackageManager": "Npm"
        }
      }
    }
    
  5. Register Services and setup app e.g.:

    using Mumrich.SpaDevMiddleware.Extensions;
    
    var builder = WebApplication.CreateBuilder(args);
    var appSettings = builder.Configuration.Get<AppSettings>();
    
    builder.SetupSpaDevMiddleware(appSettings);
    
    var app = builder.Build();
    
    app.MapSinglePageApps(appSettings);
    
    app.Run();
    
  6. 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,
      },
    });
    
  7. Run the app (dotnet run), navigate to the .NET-Web-host-Url and enjoy 👌!

Troubleshooting

  • See the working Example in the Mumrich.SpaDevMiddleware.Demo.WebHost-folder.

Credits

License

This project is licensed under the MIT License - see the LICENSE.txt file for details.

Changelog

1.5

Features
  • .NET 10 Support
Breaking Changes
  • Obsolete method RegisterSinglePageAppDevMiddleware removed
Product Compatible and additional computed target framework versions.
.NET 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 is compatible.  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.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.5.1 195 11/26/2025
1.5.1-PullRequest6.7 123 11/26/2025
1.5.1-PullRequest6.6 125 11/26/2025
1.5.1-PullRequest6.5 128 11/26/2025
1.4.1 967 5/1/2024
1.4.1-PullRequest0004.4 97 4/30/2024
1.4.1-PullRequest0004.3 89 4/30/2024
1.4.1-PullRequest0004.2 92 4/19/2024
1.4.0 559 12/12/2023
1.4.0-PullRequest0003.11 102 12/12/2023
1.4.0-PullRequest0003.10 98 12/12/2023
1.4.0-PullRequest0003.9 89 12/12/2023
1.4.0-PullRequest0003.8 103 12/12/2023
1.3.5 3,194 8/23/2023
1.3.5-PullRequest0002.1 134 8/23/2023
1.3.4 221 8/23/2023
1.3.3 329 3/24/2023
1.3.2 391 3/24/2023
1.3.1 315 3/24/2023
1.3.0-alpha.10 219 9/1/2022
1.3.0-alpha.6 209 9/1/2022
1.3.0-alpha.5 207 9/1/2022
1.2.1 427 1/12/2023
1.2.1-PullRequest0012.21 201 1/12/2023
1.2.0 2,324 10/5/2022
1.2.0-PullRequest0010.13 184 10/5/2022
1.2.0-PullRequest0009.13 182 10/5/2022
1.2.0-PullRequest0009.2 187 10/5/2022
1.1.2 589 9/28/2022
1.1.2-PullRequest0008.6 226 9/28/2022
1.1.2-PullRequest0008.5 219 9/28/2022
1.1.1 581 9/28/2022
1.1.0 582 9/28/2022
1.1.0-PullRequest0007.8 248 9/28/2022
1.0.5-PullRequest0007.7 261 9/28/2022
1.0.5-PullRequest0007.6 251 9/28/2022
1.0.5-PullRequest0006.1 216 7/14/2022
1.0.4 593 7/14/2022
1.0.4-PullRequest0006.3 221 7/14/2022
1.0.4-PullRequest0005.1 237 5/6/2022
1.0.3 584 5/6/2022
1.0.2 654 4/19/2022
1.0.0 572 4/19/2022
0.1.62 586 4/19/2022
0.1.62-PullRequest0004.3 230 4/19/2022
0.1.61 557 4/10/2022
0.1.60 557 4/10/2022
0.1.59 590 3/2/2022
0.1.54 584 3/1/2022
0.1.53 586 3/1/2022
0.1.52 587 3/1/2022
0.1.51 578 3/1/2022
0.1.50 580 3/1/2022
0.1.49 566 3/1/2022
0.1.48 583 3/1/2022
0.1.48-PullRequest0003.8 237 3/1/2022
0.1.47 596 2/24/2022
0.1.47-PullRequest0002.6 261 2/24/2022
0.1.46 587 2/23/2022
0.1.40-experimental.27 253 2/23/2022