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. Install the NuGet package
Section titled “1. Install the NuGet package”-
Add the package to your ASP.NET Core project
Terminal window dotnet add package TechGems.ViteDotNet -
Register the integration in
Program.csusing ViteDotNet;var builder = WebApplication.CreateBuilder(args);builder.Services.AddRazorPages();builder.Services.AddViteIntegration(builder.Configuration); -
Register the tag helpers in
_ViewImports.cshtml@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers@addTagHelper *, ViteDotNet
2. Install the Vite plugin
Section titled “2. Install the Vite plugin”-
Add the plugin to your SPA folder
From inside your SPA directory (e.g.
ReactApp/):Terminal window npm install vite-dotnet -
Register it in
vite.config.tsAdd 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'),],})import { defineConfig } from 'vite'import { svelte } from '@sveltejs/vite-plugin-svelte'import ViteDotNetPlugin from 'vite-dotnet'export default defineConfig({plugins: [svelte(),ViteDotNetPlugin('src/main.ts', 'app'),],})import { defineConfig } from 'vite'import vue from '@vitejs/plugin-vue'import ViteDotNetPlugin from 'vite-dotnet'export default defineConfig({plugins: [vue(),ViteDotNetPlugin('src/main.ts', 'app'),],})
3. Point the back end at your app folder
Section titled “3. Point the back end at your app folder”Add the SPA’s directory name to your configuration under the ViteDotNet section. This is
the only backend configuration required.
{ "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.