22 | Click on the Vite, ASP.NET and TypeScript logos to learn more
23 |
24 |
25 |
--------------------------------------------------------------------------------
/examples/libraries/ViteNET.React/Pages/Shared/_Layout.cshtml:
--------------------------------------------------------------------------------
1 | @inject IViteDevServerStatus ViteDevServerStatus
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | @ViewData["Title"]
11 |
12 | @* This line includes the style from the "main.ts" entrypoint *@
13 |
14 |
15 |
16 |
17 |
18 | @RenderBody()
19 |
20 |
21 |
22 |
23 |
24 | @await RenderSectionAsync("Scripts", required: false)
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/examples/net/ViteNET.BlazorServer/README.md:
--------------------------------------------------------------------------------
1 | # ViteNET
2 |
3 | This is an example project to show how to use Vite with Blazor Server.
4 |
5 | ## How to run
6 |
7 | The project is already configured to install the npm dependencies and run vite. So, simply run the ASP.NET application by running `dotnet run` or pressing `F5` in Visual Studio.
8 |
9 | ## Considerations when using Blazor
10 |
11 | Avoid running scripts directly from script tags. Blazor performs a pre-rendering process and if your scripts are executed before this process finishes, all events and references will be removed once rendering is complete.
12 |
13 | If you need to run a script after the page loads. It's recommended to import the script into from. See [index.razor](Pages/Index.razor).
14 |
15 | The Tag Helpers will be in the [_Host.cshtml](Pages/_Host.cshtml) file.
16 |
17 | Include the namespaces in the [_Imports.razor](_Imports.razor) file.
18 |
--------------------------------------------------------------------------------
/examples/libraries/ViteNET.React/Pages/Error.cshtml.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2024 Quetzal Rivera.
2 | // Licensed under the MIT License, See LICENCE in the project root for license information.
3 |
4 | using Microsoft.AspNetCore.Mvc;
5 | using Microsoft.AspNetCore.Mvc.RazorPages;
6 | using System.Diagnostics;
7 |
8 | namespace ViteNET.RazorPages.Pages;
9 |
10 | [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
11 | [IgnoreAntiforgeryToken]
12 | public class ErrorModel : PageModel
13 | {
14 | public string? RequestId { get; set; }
15 |
16 | public bool ShowRequestId => !string.IsNullOrEmpty(this.RequestId);
17 |
18 | private readonly ILogger _logger;
19 |
20 | public ErrorModel(ILogger logger)
21 | {
22 | this._logger = logger;
23 | }
24 |
25 | public void OnGet()
26 | {
27 | this.RequestId = Activity.Current?.Id ?? this.HttpContext.TraceIdentifier;
28 | }
29 | }
--------------------------------------------------------------------------------
/examples/libraries/ViteNET.Solid/Pages/Error.cshtml.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2024 Quetzal Rivera.
2 | // Licensed under the MIT License, See LICENCE in the project root for license information.
3 |
4 | using Microsoft.AspNetCore.Mvc;
5 | using Microsoft.AspNetCore.Mvc.RazorPages;
6 | using System.Diagnostics;
7 |
8 | namespace ViteNET.RazorPages.Pages;
9 |
10 | [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
11 | [IgnoreAntiforgeryToken]
12 | public class ErrorModel : PageModel
13 | {
14 | public string? RequestId { get; set; }
15 |
16 | public bool ShowRequestId => !string.IsNullOrEmpty(this.RequestId);
17 |
18 | private readonly ILogger _logger;
19 |
20 | public ErrorModel(ILogger logger)
21 | {
22 | this._logger = logger;
23 | }
24 |
25 | public void OnGet()
26 | {
27 | this.RequestId = Activity.Current?.Id ?? this.HttpContext.TraceIdentifier;
28 | }
29 | }
--------------------------------------------------------------------------------
/examples/net/ViteNET.RazorPages/Pages/Error.cshtml.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2024 Quetzal Rivera.
2 | // Licensed under the MIT License, See LICENCE in the project root for license information.
3 |
4 | using System.Diagnostics;
5 | using Microsoft.AspNetCore.Mvc;
6 | using Microsoft.AspNetCore.Mvc.RazorPages;
7 |
8 | namespace ViteNET.RazorPages.Pages;
9 |
10 | [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
11 | [IgnoreAntiforgeryToken]
12 | public class ErrorModel : PageModel
13 | {
14 | public string? RequestId { get; set; }
15 |
16 | public bool ShowRequestId => !string.IsNullOrEmpty(this.RequestId);
17 |
18 | private readonly ILogger _logger;
19 |
20 | public ErrorModel(ILogger logger)
21 | {
22 | this._logger = logger;
23 | }
24 |
25 | public void OnGet()
26 | {
27 | this.RequestId = Activity.Current?.Id ?? this.HttpContext.TraceIdentifier;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/library/Vite.AspNetCore/ViteOptions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2024 Quetzal Rivera.
2 | // Licensed under the MIT License, See LICENCE in the project root for license information.
3 |
4 | namespace Vite.AspNetCore;
5 |
6 | ///
7 | /// Options for Vite.
8 | ///
9 | public record ViteOptions
10 | {
11 | public const string Vite = "Vite";
12 |
13 | ///
14 | /// The manifest file name. Default is "manifest.json".
15 | ///
16 | public string Manifest { get; set; } = Path.Combine(".vite", "manifest.json");
17 |
18 | ///
19 | /// The subfolder where your assets will be located, including the manifest file.
20 | /// This value is relative to the web root path.
21 | ///
22 | public string? Base { get; set; }
23 |
24 | ///
25 | /// Options for the Vite Development Server.
26 | ///
27 | public ViteDevServerOptions Server { get; set; } = new();
28 | }
29 |
--------------------------------------------------------------------------------
/examples/net/ViteNET.MVC/Views/Shared/Error.cshtml:
--------------------------------------------------------------------------------
1 | @model ErrorViewModel
2 | @{
3 | ViewData["Title"] = "Error";
4 | }
5 |
6 |
Error.
7 |
An error occurred while processing your request.
8 |
9 | @if (Model.ShowRequestId)
10 | {
11 |
12 | Request ID:@Model.RequestId
13 |
14 | }
15 |
16 |
Development Mode
17 |
18 | Swapping to Development environment will display more detailed information about the error that occurred.
19 |
20 |
21 | The Development environment shouldn't be enabled for deployed applications.
22 | It can result in displaying sensitive information from exceptions to end users.
23 | For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development
24 | and restarting the app.
25 |
19 | Swapping to the Development environment displays detailed information about the error that occurred.
20 |
21 |
22 | The Development environment shouldn't be enabled for deployed applications.
23 | It can result in displaying sensitive information from exceptions to end users.
24 | For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development
25 | and restarting the app.
26 |
19 | Swapping to the Development environment displays detailed information about the error that occurred.
20 |
21 |
22 | The Development environment shouldn't be enabled for deployed applications.
23 | It can result in displaying sensitive information from exceptions to end users.
24 | For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development
25 | and restarting the app.
26 |
19 | Swapping to the Development environment displays detailed information about the error that occurred.
20 |
21 |
22 | The Development environment shouldn't be enabled for deployed applications.
23 | It can result in displaying sensitive information from exceptions to end users.
24 | For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development
25 | and restarting the app.
26 |
19 | Swapping to the Development environment displays detailed information about the error that occurred.
20 |
21 |
22 | The Development environment shouldn't be enabled for deployed applications.
23 | It can result in displaying sensitive information from exceptions to end users.
24 | For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development
25 | and restarting the app.
26 |
27 |
--------------------------------------------------------------------------------
/examples/libraries/ViteNET.Tailwind/Program.cs:
--------------------------------------------------------------------------------
1 | using Vite.AspNetCore;
2 |
3 | var builder = WebApplication.CreateBuilder(args);
4 |
5 | // Add services to the container.
6 | builder.Services.AddRazorPages();
7 |
8 | // Add Vite services to the container.
9 | builder.Services.AddViteServices(config =>
10 | {
11 | config.Base = "/dist/";
12 | config.Server.AutoRun = true;
13 | });
14 |
15 | var app = builder.Build();
16 |
17 | // Configure the HTTP request pipeline.
18 | if (!app.Environment.IsDevelopment())
19 | {
20 | app.UseExceptionHandler("/Error");
21 | // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
22 | app.UseHsts();
23 | }
24 |
25 | app.UseHttpsRedirection();
26 | app.UseStaticFiles();
27 |
28 | app.UseRouting();
29 |
30 | app.UseAuthorization();
31 |
32 | app.MapRazorPages();
33 |
34 | if (app.Environment.IsDevelopment())
35 | {
36 | app.UseWebSockets();
37 | app.UseViteDevelopmentServer();
38 | }
39 |
40 | app.Run();
41 |
--------------------------------------------------------------------------------
/examples/libraries/ViteNET.Tailwind/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "http://json.schemastore.org/launchsettings.json",
3 | "iisSettings": {
4 | "windowsAuthentication": false,
5 | "anonymousAuthentication": true,
6 | "iisExpress": {
7 | "applicationUrl": "http://localhost:26307",
8 | "sslPort": 44337
9 | }
10 | },
11 | "profiles": {
12 | "HTTPS": {
13 | "commandName": "Project",
14 | "dotnetRunMessages": true,
15 | "launchBrowser": true,
16 | "applicationUrl": "https://localhost:7032;http://localhost:5274",
17 | "environmentVariables": {
18 | "ASPNETCORE_ENVIRONMENT": "Development"
19 | }
20 | },
21 | "IIS Express": {
22 | "commandName": "IISExpress",
23 | "launchBrowser": true,
24 | "environmentVariables": {
25 | "ASPNETCORE_ENVIRONMENT": "Development"
26 | }
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/examples/libraries/ViteNET.React/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "http://json.schemastore.org/launchsettings.json",
3 | "iisSettings": {
4 | "windowsAuthentication": false,
5 | "anonymousAuthentication": true,
6 | "iisExpress": {
7 | "applicationUrl": "http://localhost:44465",
8 | "sslPort": 44342
9 | }
10 | },
11 | "profiles": {
12 | "ViteNET.React": {
13 | "commandName": "Project",
14 | "dotnetRunMessages": true,
15 | "launchBrowser": true,
16 | "applicationUrl": "https://localhost:7053;http://localhost:5044",
17 | "environmentVariables": {
18 | "ASPNETCORE_ENVIRONMENT": "Development"
19 | }
20 | },
21 | "IIS Express": {
22 | "commandName": "IISExpress",
23 | "launchBrowser": true,
24 | "environmentVariables": {
25 | "ASPNETCORE_ENVIRONMENT": "Development"
26 | }
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/examples/libraries/ViteNET.Solid/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "http://json.schemastore.org/launchsettings.json",
3 | "iisSettings": {
4 | "windowsAuthentication": false,
5 | "anonymousAuthentication": true,
6 | "iisExpress": {
7 | "applicationUrl": "http://localhost:44465",
8 | "sslPort": 44342
9 | }
10 | },
11 | "profiles": {
12 | "ViteNET.Solid": {
13 | "commandName": "Project",
14 | "dotnetRunMessages": true,
15 | "launchBrowser": true,
16 | "applicationUrl": "https://localhost:7053;http://localhost:5044",
17 | "environmentVariables": {
18 | "ASPNETCORE_ENVIRONMENT": "Development"
19 | }
20 | },
21 | "IIS Express": {
22 | "commandName": "IISExpress",
23 | "launchBrowser": true,
24 | "environmentVariables": {
25 | "ASPNETCORE_ENVIRONMENT": "Development"
26 | }
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/examples/libraries/ViteNET.Solid/Program.cs:
--------------------------------------------------------------------------------
1 | using Vite.AspNetCore;
2 |
3 | var builder = WebApplication.CreateBuilder(args);
4 |
5 | // Add services to the container.
6 | builder.Services.AddRazorPages();
7 |
8 | // Add the Vite services.
9 | builder.Services.AddViteServices(options =>
10 | {
11 | options.Server.AutoRun = true;
12 | options.Server.Https = true;
13 | });
14 |
15 | var app = builder.Build();
16 |
17 | // Configure the HTTP request pipeline.
18 | if (!app.Environment.IsDevelopment())
19 | {
20 | app.UseExceptionHandler("/Error");
21 | // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
22 | app.UseHsts();
23 | }
24 |
25 | app.UseHttpsRedirection();
26 |
27 | app.UseStaticFiles();
28 |
29 | app.UseRouting();
30 |
31 | app.UseAuthorization();
32 |
33 | app.MapRazorPages();
34 |
35 | if (app.Environment.IsDevelopment())
36 | {
37 | app.UseWebSockets();
38 | // Use Vite Dev Server as middleware.
39 | app.UseViteDevelopmentServer(true);
40 | }
41 |
42 | app.Run();
43 |
--------------------------------------------------------------------------------
/.github/workflows/publish.yaml:
--------------------------------------------------------------------------------
1 | name: Publish
2 |
3 | on:
4 | release:
5 | types: [published]
6 | workflow_dispatch:
7 |
8 | jobs:
9 | publish:
10 | name: build, pack & publish
11 | runs-on: ubuntu-latest
12 | defaults:
13 | run:
14 | working-directory: ./src
15 |
16 | steps:
17 | - uses: actions/checkout@v4
18 |
19 | - name: Setup .NET
20 | uses: actions/setup-dotnet@v4
21 | with:
22 | dotnet-version: |
23 | 8.0.x
24 |
25 | - name: Restore dependencies
26 | run: dotnet restore
27 | - name: Build
28 | run: dotnet build -c Release
29 | - name: Test
30 | run: dotnet test -c Release --no-build --verbosity normal
31 | - name: Pack
32 | run: dotnet pack library/Vite.AspNetCore -c Release -o ./nupkgs --no-build
33 | - name: Publish
34 | env:
35 | NUGET_AUTH_TOKEN: ${{ secrets.NUGET_AUTH_TOKEN }}
36 | run: dotnet nuget push ./nupkgs/*.nupkg --api-key ${{ env.NUGET_AUTH_TOKEN }} --skip-duplicate -s https://api.nuget.org/v3/index.json
37 |
--------------------------------------------------------------------------------
/examples/README.md:
--------------------------------------------------------------------------------
1 | # Examples
2 |
3 | This directory contains examples of using the `Vite.AspNetCore` package.
4 |
5 | ## Available Examples
6 |
7 | ### Examples with the .NET frameworks
8 |
9 | All of these projects implement the same website using different .NET frameworks. The site is based on the Vite templates and looks like this:
10 |
11 | 
12 |
13 | - [ViteNET.RazorPages](net/ViteNET.RazorPages/README.md) - An example of using `Vite.AspNetCore` with Razor Pages.
14 | - [ViteNET.MVC](net/ViteNET.MVC/README.md) - An example of using `Vite.AspNetCore` with MVC.
15 | - [ViteNET.BlazorServer](net/ViteNET.BlazorServer/README.md) - An example of using `Vite.AspNetCore` with Blazor Server.
16 |
17 | ### Examples with JS libraries
18 |
19 | - [ViteNET.React](libraries/ViteNET.React/README.md) - An example of using `Vite.AspNetCore` with React.
20 | - [ViteNET.Solid](libraries/ViteNET.Solid/README.md) - An example of using `Vite.AspNetCore` with SolidJS.
21 | - [ViteNET.TailwindCSS](libraries/ViteNET.Tailwind/README.md) - An example of using `Vite.AspNetCore` with Tailwind CSS.
22 |
--------------------------------------------------------------------------------
/src/tests/ViteNetProject.Tests/ViteNetProject.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | false
5 | true
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | runtime; build; native; contentfiles; analyzers; buildtransitive
15 | all
16 |
17 |
18 | runtime; build; native; contentfiles; analyzers; buildtransitive
19 | all
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/examples/libraries/ViteNET.React/Program.cs:
--------------------------------------------------------------------------------
1 | using Vite.AspNetCore;
2 |
3 | var builder = WebApplication.CreateBuilder(args);
4 |
5 | // Add services to the container.
6 | builder.Services.AddRazorPages();
7 |
8 | // Add the Vite services.
9 | builder.Services.AddViteServices(options =>
10 | {
11 | options.Server.AutoRun = true;
12 | options.Server.Https = true;
13 | options.Server.UseReactRefresh = true;
14 | });
15 |
16 | var app = builder.Build();
17 |
18 | // Configure the HTTP request pipeline.
19 | if (!app.Environment.IsDevelopment())
20 | {
21 | app.UseExceptionHandler("/Error");
22 | // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
23 | app.UseHsts();
24 | }
25 |
26 | app.UseHttpsRedirection();
27 |
28 | app.UseStaticFiles();
29 |
30 | app.UseRouting();
31 |
32 | app.UseAuthorization();
33 |
34 | app.MapRazorPages();
35 |
36 | if (app.Environment.IsDevelopment())
37 | {
38 | app.UseWebSockets();
39 | // Use Vite Dev Server as middleware.
40 | app.UseViteDevelopmentServer(true);
41 | }
42 |
43 | app.Run();
44 |
--------------------------------------------------------------------------------
/examples/net/ViteNET.MVC/Views/Shared/_Layout.cshtml.css:
--------------------------------------------------------------------------------
1 | /* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
2 | for details on configuring this project to bundle and minify static web assets. */
3 |
4 | a.navbar-brand {
5 | white-space: normal;
6 | text-align: center;
7 | word-break: break-all;
8 | }
9 |
10 | a {
11 | color: #0077cc;
12 | }
13 |
14 | .btn-primary {
15 | color: #fff;
16 | background-color: #1b6ec2;
17 | border-color: #1861ac;
18 | }
19 |
20 | .nav-pills .nav-link.active, .nav-pills .show > .nav-link {
21 | color: #fff;
22 | background-color: #1b6ec2;
23 | border-color: #1861ac;
24 | }
25 |
26 | .border-top {
27 | border-top: 1px solid #e5e5e5;
28 | }
29 | .border-bottom {
30 | border-bottom: 1px solid #e5e5e5;
31 | }
32 |
33 | .box-shadow {
34 | box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
35 | }
36 |
37 | button.accept-policy {
38 | font-size: 1rem;
39 | line-height: inherit;
40 | }
41 |
42 | .footer {
43 | position: absolute;
44 | bottom: 0;
45 | width: 100%;
46 | white-space: nowrap;
47 | line-height: 60px;
48 | }
49 |
--------------------------------------------------------------------------------
/examples/net/ViteNET.BlazorServer/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "iisSettings": {
3 | "windowsAuthentication": false,
4 | "anonymousAuthentication": true,
5 | "iisExpress": {
6 | "applicationUrl": "http://localhost:59426",
7 | "sslPort": 44361
8 | }
9 | },
10 | "profiles": {
11 | "http": {
12 | "commandName": "Project",
13 | "dotnetRunMessages": true,
14 | "launchBrowser": true,
15 | "applicationUrl": "http://localhost:5244",
16 | "environmentVariables": {
17 | "ASPNETCORE_ENVIRONMENT": "Development"
18 | }
19 | },
20 | "https": {
21 | "commandName": "Project",
22 | "dotnetRunMessages": true,
23 | "launchBrowser": true,
24 | "applicationUrl": "https://localhost:7174;http://localhost:5244",
25 | "environmentVariables": {
26 | "ASPNETCORE_ENVIRONMENT": "Development"
27 | }
28 | },
29 | "IIS Express": {
30 | "commandName": "IISExpress",
31 | "launchBrowser": true,
32 | "environmentVariables": {
33 | "ASPNETCORE_ENVIRONMENT": "Development"
34 | }
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2024 Quetzal Rivera
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/src/library/Vite.AspNetCore/Abstractions/IViteDevServerStatus.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2024 Quetzal Rivera.
2 | // Licensed under the MIT License, See LICENCE in the project root for license information.
3 |
4 | namespace Vite.AspNetCore;
5 |
6 | ///
7 | /// Provides information about the Vite development server.
8 | ///
9 | public interface IViteDevServerStatus
10 | {
11 | ///
12 | /// True if the development server is enabled, otherwise false.
13 | ///
14 | public bool IsEnabled { get; }
15 |
16 | ///
17 | /// True if the middleware is enabled, otherwise false.
18 | ///
19 | public bool IsMiddlewareEnable { get; }
20 |
21 | ///
22 | /// The URL of the Vite development server.
23 | ///
24 | public string ServerUrl { get; }
25 |
26 | ///
27 | /// The URL of the Vite development server with base path.
28 | ///
29 | public string ServerUrlWithBasePath { get; }
30 |
31 | ///
32 | /// The base path of the Vite development server.
33 | ///
34 | public string BasePath { get; }
35 | }
36 |
--------------------------------------------------------------------------------
/examples/net/ViteNET.BlazorServer/Program.cs:
--------------------------------------------------------------------------------
1 | using ViteNET.BlazorServer.Data;
2 | using Vite.AspNetCore;
3 |
4 | var builder = WebApplication.CreateBuilder(args);
5 |
6 | // Add services to the container.
7 | builder.Services.AddRazorPages();
8 | builder.Services.AddServerSideBlazor();
9 | builder.Services.AddSingleton();
10 |
11 | // Add Vite services
12 | builder.Services.AddViteServices(options =>
13 | {
14 | options.Server.Https = true;
15 | options.Server.AutoRun = true;
16 | });
17 |
18 | var app = builder.Build();
19 |
20 | // Configure the HTTP request pipeline.
21 | if (!app.Environment.IsDevelopment())
22 | {
23 | app.UseExceptionHandler("/Error");
24 | // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
25 | app.UseHsts();
26 | }
27 |
28 | app.UseHttpsRedirection();
29 |
30 | app.UseStaticFiles();
31 |
32 | app.UseRouting();
33 |
34 | app.MapBlazorHub();
35 | app.MapFallbackToPage("/_Host");
36 |
37 | if (app.Environment.IsDevelopment())
38 | {
39 | app.UseWebSockets();
40 | // Use Vite Dev Server as middleware.
41 | app.UseViteDevelopmentServer(true);
42 | }
43 |
44 | app.Run();
45 |
--------------------------------------------------------------------------------
/examples/net/ViteNET.RazorPages/Program.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2024 Quetzal Rivera.
2 | // Licensed under the MIT License, See LICENCE in the project root for license information.
3 |
4 | using Vite.AspNetCore;
5 |
6 | var builder = WebApplication.CreateBuilder(args);
7 |
8 | // Add services to the container.
9 | builder.Services.AddRazorPages();
10 |
11 | // Add the Vite services.
12 | builder.Services.AddViteServices(options =>
13 | {
14 | options.Server.AutoRun = true;
15 | options.Server.Https = true;
16 | });
17 |
18 | var app = builder.Build();
19 |
20 | // Configure the HTTP request pipeline.
21 |
22 | if (!app.Environment.IsDevelopment())
23 | {
24 | app.UseExceptionHandler("/Error");
25 | // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
26 | app.UseHsts();
27 | }
28 |
29 | app.UseHttpsRedirection();
30 | app.UseStaticFiles();
31 | app.UseRouting();
32 | app.UseAuthorization();
33 |
34 | app.MapRazorPages();
35 |
36 | if (app.Environment.IsDevelopment())
37 | {
38 | app.UseWebSockets();
39 | // Use Vite Dev Server as middleware.
40 | app.UseViteDevelopmentServer(true);
41 | }
42 |
43 | app.Run();
44 |
--------------------------------------------------------------------------------
/examples/net/ViteNET.MVC/Controllers/HomeController.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2024 Quetzal Rivera.
2 | // Licensed under the MIT License, See LICENCE in the project root for license information.
3 |
4 | using System.Diagnostics;
5 | using Microsoft.AspNetCore.Mvc;
6 | using ViteNET.MVC.Models;
7 |
8 | namespace ViteNET.MVC.Controllers;
9 |
10 | public class HomeController : Controller
11 | {
12 | private readonly ILogger _logger;
13 |
14 | public HomeController(ILogger logger)
15 | {
16 | this._logger = logger;
17 | }
18 |
19 | public IActionResult Index()
20 | {
21 | return this.View();
22 | }
23 |
24 | [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
25 | public IActionResult Error()
26 | {
27 | return this.View(
28 | new ErrorViewModel
29 | {
30 | RequestId = Activity.Current?.Id ?? this.HttpContext.TraceIdentifier
31 | }
32 | );
33 | }
34 |
35 | [HttpGet("/hello")]
36 | [HttpPost("/hello")]
37 | public IActionResult Hello()
38 | {
39 | string randomString = Guid.NewGuid().ToString();
40 | return this.Ok($"Hello World! GUID: {randomString}");
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/examples/net/ViteNET.MVC/Program.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2024 Quetzal Rivera.
2 | // Licensed under the MIT License, See LICENCE in the project root for license information.
3 |
4 | using Vite.AspNetCore;
5 |
6 | var builder = WebApplication.CreateBuilder(args);
7 |
8 | // Add services to the container.
9 | builder.Services.AddControllersWithViews();
10 | // Add the Vite services.
11 | builder.Services.AddViteServices(options =>
12 | {
13 | options.Server.AutoRun = true;
14 | options.Server.Https = true;
15 | });
16 |
17 | var app = builder.Build();
18 |
19 | // Configure the HTTP request pipeline.
20 |
21 | if (!app.Environment.IsDevelopment())
22 | {
23 | app.UseExceptionHandler("/Home/Error");
24 | // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
25 | app.UseHsts();
26 | }
27 |
28 | app.UseHttpsRedirection();
29 | app.UseStaticFiles();
30 |
31 | app.UseRouting();
32 | app.UseAuthorization();
33 |
34 | app.MapControllerRoute(
35 | name: "default",
36 | pattern: "{controller=Home}/{action=Index}/{id?}");
37 |
38 | if (app.Environment.IsDevelopment())
39 | {
40 | app.UseWebSockets();
41 | // Use Vite Dev Server as middleware.
42 | app.UseViteDevelopmentServer(true);
43 | }
44 |
45 | app.Run();
46 |
--------------------------------------------------------------------------------
/examples/net/ViteNET.MVC/Assets/public/dotnet.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/examples/libraries/ViteNET.React/Assets/App.tsx:
--------------------------------------------------------------------------------
1 | import { useState } from 'react'
2 | import reactLogo from './assets/react.svg'
3 | import viteLogo from '/vite.svg'
4 | import dotnetLogo from '/dotnet.svg'
5 | import './App.css'
6 |
7 | function App() {
8 | const [count, setCount] = useState(0)
9 |
10 | return (
11 | <>
12 |
24 | Click on the Vite, ASP.NET and TypeScript logos to learn more
25 |
26 |
27 |
28 |
29 | @code {
30 | private ElementReference counterButton;
31 |
32 | protected override async Task OnAfterRenderAsync(bool firstRender)
33 | {
34 | if (firstRender)
35 | {
36 | var mainModule = ViteStatusService.IsEnabled
37 | ? $"{ViteStatusService.ServerUrlWithBasePath}/main.ts"
38 | : $"/{Manifest["main.ts"]!.File}";
39 | await JS.InvokeAsync("import", mainModule);
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/library/Vite.AspNetCore/Abstractions/IViteManifest.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2024 Quetzal Rivera.
2 | // Licensed under the MIT License, See LICENCE in the project root for license information.
3 |
4 | namespace Vite.AspNetCore;
5 |
6 | ///
7 | /// Represents a Vite manifest file.
8 | ///
9 | public interface IViteManifest : IEnumerable
10 | {
11 | ///
12 | /// Gets the Vite chunk for the specified entry point if it exists.
13 | /// If Dev Server is enabled, this will always return .
14 | ///
15 | ///
16 | /// The chunk if it exists, otherwise .
17 | IViteChunk? this[string key] { get; }
18 |
19 | ///
20 | /// Gets an enumerable collection that contains the chunk keys in the manifest.
21 | ///
22 | /// An enumerable collection that contains the chunk keys in the manifest.
23 | IEnumerable Keys { get; }
24 |
25 | ///
26 | /// Determines whether the manifest contains a chunk with the specified key entry.
27 | ///
28 | /// The eky entry to locate.
29 | /// true if the manifest contains a chunk with the specified key entry; otherwise, false.
30 | bool ContainsKey(string key);
31 | }
32 |
--------------------------------------------------------------------------------
/examples/net/ViteNET.BlazorServer/Pages/_Host.cshtml:
--------------------------------------------------------------------------------
1 | @page "/"
2 | @using Microsoft.AspNetCore.Components.Web
3 | @namespace ViteNET.BlazorServer.Pages
4 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
5 | @addTagHelper *, Vite.AspNetCore
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | @* This line includes the style from the "main.scss" entrypoint *@
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 | An error has occurred. This application may no longer respond until reloaded.
25 |
26 |
27 | An unhandled exception has occurred. See browser dev tools for details.
28 |
29 | Reload
30 | 🗙
31 |
30 | Swapping to the Development environment displays detailed information about the error that occurred.
31 |
32 |
33 | The Development environment shouldn't be enabled for deployed applications.
34 | It can result in displaying sensitive information from exceptions to end users.
35 | For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development
36 | and restarting the app.
37 |