Skip to content

Installation

Vite.NET has two halves: a NuGet package for your ASP.NET Core app, and a Vite plugin for your SPA. This page installs both. If you are starting from scratch, the Quick Start walks through the whole project layout.

  1. Add the package to your ASP.NET Core project

    Terminal window
    dotnet add package TechGems.ViteDotNet
  2. Register the integration in Program.cs

    using ViteDotNet;
    var builder = WebApplication.CreateBuilder(args);
    builder.Services.AddRazorPages();
    builder.Services.AddViteIntegration(builder.Configuration);
  3. Register the tag helpers in _ViewImports.cshtml

    @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
    @addTagHelper *, ViteDotNet
  1. Add the plugin to your SPA folder

    From inside your SPA directory (e.g. ReactApp/):

    Terminal window
    npm install vite-dotnet
  2. Register it in vite.config.ts

    Add the plugin after your framework plugin, passing your entrypoint and the id of the element the SPA mounts into:

    import { defineConfig } from 'vite'
    import react from '@vitejs/plugin-react'
    import ViteDotNetPlugin from 'vite-dotnet'
    export default defineConfig({
    plugins: [
    react(),
    ViteDotNetPlugin('src/main.tsx', 'root'),
    ],
    })

Add the SPA’s directory name to your configuration under the ViteDotNet section. This is the only backend configuration required.

appsettings.Development.json
{
"ViteDotNet": "ReactApp"
}

That’s it — everything else (entrypoint, container element id, dev-server port, whether the app is React) is generated by the plugin at dev-server start and build time. Continue to the Quick Start to render your SPA into a page.