AspSpaService 1.0.3

.NET 6.0
dotnet add package AspSpaService --version 1.0.3
NuGet\Install-Package AspSpaService -Version 1.0.3
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.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AspSpaService --version 1.0.3
#r "nuget: AspSpaService, 1.0.3"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. 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.3

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

AspSpaService

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

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)
        {
            // ---- 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(
                        // 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

Vue

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    // ---- 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("yarn", "serve", p, new Dictionary<string,string>(), TimeSpan.FromSeconds(15), "Timeout has been exceeded");
        }
    );
}

Vite

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    // ---- 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)
{
    // ---- 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)
{
    // ---- 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)
{
    // ---- 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 Versions
.NET net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
Compatible target framework(s)
Additional computed target framework(s)
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.3 310 1/19/2022
1.0.2 1,189 8/1/2020
1.0.1 386 7/15/2020
1.0.0 489 7/12/2020