AspSpaService 1.0.6

dotnet add package AspSpaService --version 1.0.6
NuGet\Install-Package AspSpaService -Version 1.0.6
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="AspSpaService" Version="1.0.6" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AspSpaService --version 1.0.6
#r "nuget: AspSpaService, 1.0.6"
#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.
// Install AspSpaService as a Cake Addin
#addin nuget:?package=AspSpaService&version=1.0.6

// Install AspSpaService as a Cake Tool
#tool nuget:?package=AspSpaService&version=1.0.6

AspSpaService

<a href="https://www.nuget.org/packages/AspSpaService"> <img alt="Nuget (with prereleases)" src="https://img.shields.io/nuget/vpre/AspSpaService"> </a> <a href="https://www.nuget.org/packages/AspSpaService"> <img alt="Nuget" src="https://img.shields.io/nuget/dt/AspSpaService"> </a>

The Asp Net Core plugin for integrating SPA application with Asp Net Core. Simplify SPA site development This plugin can be used with any web framework in same manner.

Usage

Install package via NuGet

dotnet add package AspSpaService

Install all the dependencies defined in Your SPA application

cd <SPA application path>
yarn // or npm install or pnpm install

Change your Startup.cs configuration file as follows:

using AspSpaService;
    public class Startup
    {
        public void ConfigureServices(IServiceCollection services)
        {
            // ---- Your code -----------//
            services.AddNodeRunner();
        }

        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostApplicationLifetime hostApplicationLifetime)
        {
            // ---- Your code -----------//
            //this block starts vue spa application
            var wd = Directory.GetCurrentDirectory();
            var p = Path.Combine(wd,"samples", "hello-vite"); // path to your vuejs project
            app.UseSpa(
                spa => {
                    spa.UseAspSpaDevelopmentServer(
                        hostApplicationLifetime,
                        // command for nodejs process
                        // string
                        "yarn",
                        // argument for nodejs process
                        // string
                        "dev",
                        // working directory
                        // string
                        p,
                        // environment variables
                        new Dictionary<string,string>(),
                        // timeout for waiting node js process is ready to use
                         TimeSpan.FromSeconds(15),
                         // message when timeout has been exceeded
                         // has defaul value = "Timeout has been exceeded" (can be ommited!)
                         // string
                          "Timeout has been exceeded",
                          //logInformation for node js process
                          // bool (true by default)
                          true,
                          //logError for node js process
                          // some bundler emits many error strings during compilation
                          // bool (false by default)
                          false,
                          //unsubscribeWhenReady
                          // stop logging nodejs output when it ready to use
                          // bool (true by default)
                          true
                          );
                }
            );
        }
    }

This library starts NodeJS process, and waiting for it emits line with served valid Uri

Sample configuratons

In folder sample/webapi has the web empty project that shows, how to use your favorite web framework with asp. This code should be placed in Startup class in Configure method. Because of nodejs process requires correct dispose when application stopped, we need include IHostApplicationLifetime parameter in initialization code to fire nodejs process dispose code

Vue

public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostApplicationLifetime hostApplicationLifetime)
{
    // ---- Your code -----------//
    //this block starts vue spa application
    var wd = Directory.GetCurrentDirectory();
    var p = Path.Combine(wd,"samples", "hello-vue"); // path to your vuejs project
    app.UseSpa(
        spa => {
            spa.UseAspSpaDevelopmentServer(hostApplicationLifetime, "yarn", "serve", p, new Dictionary<string,string>(), TimeSpan.FromSeconds(15), "Timeout has been exceeded");
        }
    );
}

Vite

public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostApplicationLifetime hostApplicationLifetime)
{
    // ---- Your code -----------//
    //this block starts vite spa application
    var wd = Directory.GetCurrentDirectory();
    var p = Path.Combine(wd,"samples", "hello-vite"); // path to your vitejs project
    app.UseSpa(
        spa => {
            spa.UseAspSpaDevelopmentServer("yarn", "dev", p, new Dictionary<string,string>(), TimeSpan.FromSeconds(15), "Timeout has been exceeded");
        }
    );
}

Nuxt

public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostApplicationLifetime hostApplicationLifetime)
{
    // ---- Your code -----------//
    //this block starts nuxt spa application
    var wd = Directory.GetCurrentDirectory();
    var p = Path.Combine(wd,"samples", "hello-nuxt"); // path to your nuxt project
    app.UseSpa(
        spa => {
            spa.UseAspSpaDevelopmentServer("yarn", "dev", p, new Dictionary<string,string>(), TimeSpan.FromSeconds(15), "Timeout has been exceeded");
        }
    );
}

React

public void Configure(IApplicationBuilder app, IWebHostEnvironment env,IHostApplicationLifetime hostApplicationLifetime)
{
    // ---- Your code -----------//
    //this block starts react spa application
    var wd = Directory.GetCurrentDirectory();
    var p = Path.Combine(wd,"samples", "hello-react"); // path to your react project
    app.UseSpa(
        spa => {
            spa.UseAspSpaDevelopmentServer("yarn", "start", p, new Dictionary<string,string>(), TimeSpan.FromSeconds(15), "Timeout has been exceeded");
        }
    );
}

Svelte

Note. Because Svelte and AspNetCore, by default, use the same port (5000), the port of Svelte should be changed!!!

public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostApplicationLifetime hostApplicationLifetime)
{
    // ---- Your code -----------//
    //this block starts svelte spa application
    var wd = Directory.GetCurrentDirectory();
    var p = Path.Combine(wd,"samples", "hello-svelte"); // path to your svelte project
    app.UseSpa(
        spa => {
            spa.UseAspSpaDevelopmentServer("yarn", "dev", p, new Dictionary<string,string>(), TimeSpan.FromSeconds(15), "Timeout has been exceeded");
        }
    );
}

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. 
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.0.6 162 12/29/2023
1.0.5 153 8/30/2023
1.0.4 154 8/5/2023
1.0.3 487 1/19/2022
1.0.2 5,623 8/1/2020
1.0.1 487 7/15/2020
1.0.0 577 7/12/2020