ViteIntegration 1.0.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package ViteIntegration --version 1.0.0
NuGet\Install-Package ViteIntegration -Version 1.0.0
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="ViteIntegration" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ViteIntegration --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: ViteIntegration, 1.0.0"
#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 ViteIntegration as a Cake Addin #addin nuget:?package=ViteIntegration&version=1.0.0 // Install ViteIntegration as a Cake Tool #tool nuget:?package=ViteIntegration&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
ViteIntegration
Integrate Vite with ASP.NET Core.
Prerequisites
- .NET 6 or later is required (for now).
- Only tested with MVC projects, but should work with Razor Pages as well.
- You'll need a Vite project setup. See Recommended Vite Setup for more information.
Installation
- Install the ViteIntegration NuGet package.
- Add something like the following to your
Program.cs
file:
//file: Program.cs
using ViteIntegration;
builder.Services.AddViteIntegration(options => {
// Required: Add assets from your Vite manifest file. In your vite.config.ts file, you must set manifest: true.
// The manifest file will be named `manifest.json` and will be placed in the `outDir`. The path should be defined relative to the application working directory.
options.AddAssetsFromManifest("wwwroot/manifest.json");
// Alternative: Add asset definitions manually, you can add as many as you want.
options.AddAsset("src/site.ts", new ViteAsset { Src = "src/site.ts", File = "assets/site.js" });
// Optional: Let ViteIntegration know the URL of your Vite dev server. This is only used in Development, and it only used when writing <script> tags.
options.WithDevServer("http://localhost:5173");
// Optional: Include these assets on every Razor page. This is useful for things like your main entry point, or a shared CSS file.
options.WithDefaultAssets("src/site.ts");
// Optional: Configure <script> tag attributes, values shown below are the defaults if you omit this call.
options.WithScriptOptions(isModule: true, isDefer: true);
});
If you have a Startup.cs
file, the above configuration can also add the following to your ConfigureServices
method with changes since builder.Services
will just be services
.
Recommended Vite Setup
The following is a minimal setup for a Vite project that will work with this library. See the comments for explanations.
//file: vite.config.ts
import {defineConfig} from "vite";
export default defineConfig({
build: {
// Not required, but assuming your Vite project is within your ASP.NET Core project, this will write Vite output to the default location for ASP.NET Core static files.
// You could set this to anything, (or even leave it as the default 'dist') but you will need to configure the ASP.NET Core static files middleware to serve the files from this directory.
outDir: "wwwroot",
// Not required, but cleans out the output directory before each build.
emptyOutDir: true,
// Required if using AddAssetsFromManifest(), which reads the manifest file to determine which assets to include. You can also specify assets manually.
manifest: true,
rollupOptions: {
output: {
// Default settings for ViteIntegration are to write <script> tags with type="module" which requires ES modules.
format: "esm"
}
}
}
});
License
This project is licensed under the MIT license. Full terms are available in the license file.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0.0)
- Microsoft.Extensions.FileProviders.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Options (>= 6.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.