Skip to content
Helpers for building single-page applications on ASP.NET MVC Core using Vue Cli or Quasar Cli.
Branch: master
Clone or download
Latest commit dde3927 Nov 4, 2019

VueCliMiddleware - Supporting Vue Cli and Quasar Cli

This is a stand-alone module to add Vue Cli and Quasar Cli support to AspNet Core.

See the examples here:

ASP.NET 3.0 Preview Endpoint Routing (experimental)

First, be sure to switch Vue Cli or Quasar Cli to output distribution files to wwwroot directly (not dist).

  • Quasar CLI: regex: "Compiled successfully"
  • Vue CLI: regex: default or "running at" or "Starting development server"

the reason for Starting development server ,the npm-script running checkpoint: Although the dev server may eventually tell us the URL it's listening on, it doesn't do so until it's finished compiling, and even then only if there were no compiler warnings. So instead of waiting for that, consider it ready as soon as it starts listening for requests.see the codes

See Migrating Asp.Net 2.2 to 3.0 Endpoint Routing

// To use with EndpointRouting

            app.UseEndpoints(endpoints =>

                // initialize vue cli middleware
                if (System.Diagnostics.Debugger.IsAttached)
                    endpoints.MapToVueCliProxy("{*path}", new SpaOptions { SourcePath = "ClientApp" }, "dev", regex: "Compiled successfully");
                    // note: output of vue cli or quasar cli should be wwwroot

ASP.NET 2.2 Usage Example

    using VueCliMiddleware;

    public class Startup
        public Startup(IConfiguration configuration)
            Configuration = configuration;

        public IConfiguration Configuration { get; }

        public virtual void ConfigureServices(IServiceCollection services)
           services.AddMvc(); // etc
           // Need to register ISpaStaticFileProvider for UseSpaStaticFiles middleware to work
           services.AddSpaStaticFiles(configuration =>
               configuration.RootPath = "ClientApp/dist";

        public virtual void Configure(IApplicationBuilder app, IHostingEnvironment env)
           // your config opts...
		   // optional basepath
		   // app.UsePathBase("/myapp");

           // add static files from SPA (/dist)

          app.UseMvc(routes => /* configure*/ );

          app.UseSpa(spa =>
                spa.Options.SourcePath = "ClientApp";
                if (env.IsDevelopment())
                    spa.UseVueCli(npmScript: "serve", port: 8080); // optional port

CSPROJ Configuration

You may also need to add the following tasks to your csproj file. This are similar to what are found in the default ASPNETSPA templates.

    <!-- Typescript/Javascript Client Configuration -->
  <Target Name="DebugEnsureNodeEnv" BeforeTargets="Build">
    <!-- Build Target:  Ensure Node.js is installed -->
    <Exec Command="node --version" ContinueOnError="true">
      <Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
    <Error Condition="'$(ErrorCode)' != '0'" Text="Node.js is required to build and run this project. To continue, please install Node.js from, and then restart your command prompt or IDE." />

  <Target Name="DebugEnsureNpm" AfterTargets="DebugEnsureNodeEnv">
    <!-- Build Target:  Ensure Node.js is installed -->
    <Exec Command="npm --version" ContinueOnError="true">
      <Output TaskParameter="ExitCode" PropertyName="ErrorCode" />

  <Target Name="EnsureNodeModulesInstalled" BeforeTargets="Build" Inputs="package.json" Outputs="packages-lock.json">
    <!-- Build Target: Restore NPM packages using npm -->
    <Message Importance="high" Text="Restoring dependencies using 'npm'. This may take several minutes..." />

    <Exec WorkingDirectory="$(SpaRoot)" Command="npm install" />

  <Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
    <!-- Build Target: Run webpack dist build -->
    <Message Importance="high" Text="Running npm build..." />
    <Exec WorkingDirectory="$(SpaRoot)" Command="npm run build" />

    <!-- Include the newly-built files in the publish output -->
      <DistFiles Include="$(SpaRoot)dist\**" />
      <ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">


Due to the discussion here, it was decided to not be included in the Microsoft owned package.

You can’t perform that action at this time.