Skip to content

rmacfie/vitefest

Repository files navigation

ViteFest

Utilize Vite build assets in ASP.NET Core and other .NET applications.

ViteFest.AspNetCore

ASP.NET Core

vite.config.ts:

import { defineConfig } from 'vite';

export default defineConfig({
  base: '/dist/',
  build: {
    outDir: 'wwwroot/dist',
    manifest: 'vite-manifest.json',
    rollupOptions: {
      input: ['ClientApp/shared.ts', 'ClientApp/login.ts']
    }
  }
});

Program.cs:

builder.Services.AddViteFest(o =>
{
    o.ManifestFile = "dist/vite-manifest.json";
    o.BaseUrl = "/dist/";
});

SomePage.cshtml or SomePage.razor:

@inject ViteFest.IVite Vite

<script src='@Vite.GetUrl("ClientApp/shared.ts")'></script>
<script src='@Vite.GetUrl("ClientApp/login.ts")'></script>

@foreach (var cssUrl in Vite.GetCssUrls("ClientApp/shared.ts"))
{
  <link rel="stylesheet" href="@cssUrl" />
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages