Soukoku.AspNet.Mvc.ViteIntegration 1.0.0-alpha17

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

// Install Soukoku.AspNet.Mvc.ViteIntegration as a Cake Tool
#tool nuget:?package=Soukoku.AspNet.Mvc.ViteIntegration&version=1.0.0-alpha17&prerelease                

This is a lib for integrating a Vite app in an aspnet or aspnet core app. Aspnet app provides the backend while a Vite SPA app provides the frontend.

For aspnet core

Add the NuGet package Soukoku.AspNetCore.ViteIntegration, then in the typical Program.cs file, register it with

var builder = WebApplication.CreateBuilder(args);

// depends on the actual dev server url
builder.Services.AddViteManifest("https://localhost:3000");

In a controller method that should serve the SPA view, use "VuePage" and give it a VitePageMvcModel.

[HttpGet("{*anyPath}")]
public ActionResult Index(string? anyPath = null)
{
    var model = new VitePageMvcModel
    {
        Entry = "src/main.ts",
        UseAntiforgery = true, // if necessary
        PageData = new         // as needed
        {
            Property = "howdy"
        }
    };
    return View("VuePage", model);
}

Run the typical npm run dev in your vite app folder, then debug in aspnet as usual.

For aspnet mvc (fx 4.6.2+)

Add the NuGet package Soukoku.AspNet.Mvc.ViteIntegration, then in the typical RouteConfig.cs file, register it with.

// assuming "dist" output content is placed in site root
var manifestPath = HostingEnvironment.MapPath("~/.vite/manifest.json");
// depends on the actual dev server url
routes.MapViteSpaProxy(manifestPath, "https://localhost:3000");

In a controller method that should serve the SPA view, use "VuePage" and give it a VitePageMvcModel.

public ActionResult Index()
{
    var model = new VitePageMvcModel
    {
        Entry = "src/main.ts",
        UseAntiforgery = true, // if necessary
        PageData = new         // as needed
        {
            Property = "howdy"
        }
    };
    return View("VuePage", model);
}

For dev time, ensure these are in the web.config file

  
  <location path="@id">
    <system.web>
      <httpRuntime requestPathInvalidCharacters="&lt;,&gt;,*,%,&amp;,\,?" />
    </system.web>
  </location>
  
  
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <handlers>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
  </system.webServer>

Run the typical npm run dev in your vite app folder, then debug in aspnet as usual.

Examples

A more complete example is in the repo.

Product Compatible and additional computed target framework versions.
.NET Framework net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 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.0-alpha17 58 9/15/2024