Proggmatic.SpaServices.VueCli 8.0.0

dotnet add package Proggmatic.SpaServices.VueCli --version 8.0.0
NuGet\Install-Package Proggmatic.SpaServices.VueCli -Version 8.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="Proggmatic.SpaServices.VueCli" Version="8.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Proggmatic.SpaServices.VueCli --version 8.0.0
#r "nuget: Proggmatic.SpaServices.VueCli, 8.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 Proggmatic.SpaServices.VueCli as a Cake Addin
#addin nuget:?package=Proggmatic.SpaServices.VueCli&version=8.0.0

// Install Proggmatic.SpaServices.VueCli as a Cake Tool
#tool nuget:?package=Proggmatic.SpaServices.VueCli&version=8.0.0

Vue CLI Server Middleware

alternate text is missing from this package README image

Provides dev-time support for Vue CLI in ASP.NET Core's SPA scenarios.

Only .NET 6.0 and higher will be supported.

This is mostly copied and modified from ASP.net Core's implementation for React: https://github.com/dotnet/aspnetcore/tree/main/src/Middleware/Spa/SpaServices.Extensions/src/ReactDevelopmentServer.

Usage

ASP.NET Project

Install the Proggmatic.SpaServices.VueCli NuGet package on the ASP.NET Core web project, then modify the Startup.cs file similar to the following.

using Proggmatic.SpaServices.VueCli;                  //-- new addition --//


public void ConfigureServices(IServiceCollection services)
{
  // ... other .NET configuration skipped


  //-- new addition --//
  services.AddSpaStaticFiles(configuration =>
  {
    configuration.RootPath = "ClientApp/dist";
  });
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
  // ... other .NET configuration skipped here

  app.UseStaticFiles();

  app.UseSpaStaticFiles();                            //-- new addition --//
  
  // ... more default stuff

  app.UseEndpoints(routes =>
  {
      // you app routes...
  }


  //-- new addition --//
  app.UseSpa(spa =>
  {
    // spa.Options.SourcePath = "ClientApp";          // Optional. If this string is commented, "ClientApp" will be used
    // spa.Options.PackageManagerCommand = "yarn";    // Optional. If this string is commented, "npm" will be used. You may use yarn instead of npm.

    if (env.IsDevelopment())
    {
      spa.UseVueCliServer();
      
      // Or to build not by starting this application but manually uncomment next lines and comment line above
      // spa.ApplicationBuilder.UseFixSpaPathBaseBugMiddleware();     // Uncomment this, if you want to use non-root url for proxying (like http://localhost:8080/my-custom-path)
      // spa.UseProxyToSpaDevelopmentServer("http://localhost:8080");
    }
  });
}

Vue Project

The vue project is a typical one created by vue cli such as vue create ClientApp and placed inside the ASPNET site's project folder.

.csproj Configuration

If publishing the ASPNET Core's project is needed then edit the .csproj file like below. Change SpaRoot value to the actual vue project's folder name. Change yarn to npm if necessary.

  <PropertyGroup>
    <SpaRoot>ClientApp\</SpaRoot>
    <DefaultItemExcludes>$(DefaultItemExcludes);$(SpaRoot)node_modules\**</DefaultItemExcludes>
  </PropertyGroup>

  <ItemGroup>
    
    <Content Remove="$(SpaRoot)**" />
    <None Remove="$(SpaRoot)**" />
    <None Include="$(SpaRoot)**" Exclude="$(SpaRoot)node_modules\**" />
  </ItemGroup>

  <Target Name="DebugEnsureNodeEnv" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('$(SpaRoot)node_modules') ">

    
    <Exec Command="node --version" ContinueOnError="true">
      <Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
    </Exec>
    <Error Condition="'$(ErrorCode)' != '0'" Text="Node.js is required to build and run this project. To continue, please install Node.js from https://nodejs.org/, and then restart your command prompt or IDE." />

    
    <Exec Command="yarn --version" ContinueOnError="true">
      <Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
    </Exec>
    <Error Condition="'$(ErrorCode)' != '0'" Text="Yarn is required to build and run this project." />
    <Message Importance="high" Text="Restoring dependencies using 'yarn'. This may take several minutes..." />
    <Exec WorkingDirectory="$(SpaRoot)" Command="yarn install" />
  </Target>

  <Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
    
    <Exec WorkingDirectory="$(SpaRoot)" Command="yarn install" />
    <Exec WorkingDirectory="$(SpaRoot)" Command="yarn build" />

    
    <ItemGroup>
      <DistFiles Include="$(SpaRoot)dist\**" />
      <ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
        <RelativePath>%(DistFiles.Identity)</RelativePath>
        <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
        <ExcludeFromSingleFile>true</ExcludeFromSingleFile>
      </ResolvedFileToPublish>
    </ItemGroup>
  </Target>

Notes

  • To get hot-module-reloading to work, both Vue's dev server and aspnet's site need to be on the same protocol (http or https).
  • When using https in dev server, it needs to use a trusted certificate or aspnet will refuse to connect to it.
  • Progress of serve command writes to logger with name Microsoft.AspNetCore.SpaServices.
  • Since dev server's progress is written to stderror there will be lots of "fail"s logged in dotnet. To minimize this add progress: false to the devServer section in vue.config.js file. See this page on how to add it.
Product 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 is compatible.  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 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
8.0.0 265 11/17/2023
7.0.0 723 11/10/2022
6.0.0 2,829 11/16/2021
5.0.9 1,565 8/20/2021
5.0.7 422 6/14/2021
5.0.5 407 4/8/2021
5.0.4.1 3,088 3/16/2021
5.0.3 364 2/12/2021
5.0.1 553 12/9/2020
5.0.0 422 11/17/2020

Updated to .NET 8.0.0