Vue.js 安装Asp.Net核心应用程序以启动带有webpack和HMR的Vue SPA

Vue.js 安装Asp.Net核心应用程序以启动带有webpack和HMR的Vue SPA,vue.js,asp.net-core,Vue.js,Asp.net Core,我正在尝试使用ASP.NET Core 3.0和Vue设置一个新的应用程序。我一直在努力正确地设置它,以便后端和前端服务器能够正确地集成,具有正确的路由和工作HMR。我现在确实可以用了,但我不知道这是不是正确的方法,而且我觉得有些部分没有发挥应有的作用 我当前的设置: Webpack配置为将文件输出到wwwroot。我还有HMR和 运行时启用: 在Startup.cs中: public void ConfigureServices(IServiceCollection services)

我正在尝试使用ASP.NET Core 3.0和Vue设置一个新的应用程序。我一直在努力正确地设置它,以便后端和前端服务器能够正确地集成,具有正确的路由和工作HMR。我现在确实可以用了,但我不知道这是不是正确的方法,而且我觉得有些部分没有发挥应有的作用

我当前的设置:

Webpack配置为将文件输出到
wwwroot
。我还有HMR和 运行时启用:

Startup.cs
中:

 public void ConfigureServices(IServiceCollection services)
        {
          .....
            services.AddSpaStaticFiles(configuration =>
            {
                configuration.RootPath = "wwwroot";
            });
        }
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
       {
           app.UseStaticFiles();
            app.UseSpaStaticFiles();

            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller}/{action=Index}/{id?}");

                if (env.IsDevelopment())
                {
                    if (System.Diagnostics.Debugger.IsAttached)
                    {
                        // run the dev server 
                        endpoints.MapToVueCliProxy("{*path}", new SpaOptions { SourcePath = "ClientApp" },
                            npmScript: "serve", regex: "Compiled successfully");
                    }
                }
                // serve index.html file when no api endpoints are matched
                endpoints.MapFallbackToFile("index.html");
       }
我的此设置问题:

  • 通常,HMR在内存中构建文件,但我在这里设置了它,将新文件写入文件系统,以便后端服务器可以访问和服务
    index.html
    。这是可行的,但是现在我的文件系统中有大量的膨胀。有没有办法将内存中的HMR与ASP.NET服务器结合使用
  • 代理并不总是可靠的;我经常在控制台中遇到无法连接到服务器的错误。此外,
    index.html
    有时会被缓存,我必须进行硬重新加载。能不能让它变得更可靠

我没有使用您正在使用的.net核心内容,看起来它是专门为这项工作设计的。但我的工作流程也很有效,就是让express坐在API和spa前面,将spa请求反向代理到webpack开发服务器。您还需要提交websocket请求。如果你感兴趣的话,我可以发布我的脚本。@stellr42-你明白了吗?我对.Net core 3.1也有同样的问题。我没有使用您正在使用的.Net core内容,看起来它是专门为这项工作设计的。但我的工作流程也很有效,就是让express坐在API和spa前面,将spa请求反向代理到webpack开发服务器。您还需要提交websocket请求。如果你感兴趣的话,我可以发布我的脚本。@stellr42-你明白了吗?我对.NETCore3.1也有同样的问题。
 public void ConfigureServices(IServiceCollection services)
        {
          .....
            services.AddSpaStaticFiles(configuration =>
            {
                configuration.RootPath = "wwwroot";
            });
        }
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
       {
           app.UseStaticFiles();
            app.UseSpaStaticFiles();

            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller}/{action=Index}/{id?}");

                if (env.IsDevelopment())
                {
                    if (System.Diagnostics.Debugger.IsAttached)
                    {
                        // run the dev server 
                        endpoints.MapToVueCliProxy("{*path}", new SpaOptions { SourcePath = "ClientApp" },
                            npmScript: "serve", regex: "Compiled successfully");
                    }
                }
                // serve index.html file when no api endpoints are matched
                endpoints.MapFallbackToFile("index.html");
       }