Angular 6 更新后实时重新加载不再有效

Live reload no longer works after Angular 6 update

解决方法实际上是删除ClientApp/dist文件夹。但是我每次"publish",都得重新删除

你知道怎么解决吗?

我的 Startup.cs 使用这个文件夹...

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

    // In production, the Angular files will be served from this directory
    services.AddSpaStaticFiles(configuration =>
    {
        configuration.RootPath = "ClientApp/dist";
    });
} 

使用 dotnet new angular 模板

并遵循本指南:https://update.angular.io/

并从 ClientApp/package.json

中的 "scripts" 集合中删除 --extract-css
"scripts": {
    "ng": "ng",
    "start": "ng serve --extract-css",
    "build": "ng build --extract-css",
    "build:ssr": "npm run build -- --app=ssr --output-hashing=media",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
},

我能够从 angular 5 成功升级到 6,两个 dotnet 核心的实时重新加载功能和 angular 应用程序仍然可用。


关于让您的项目正常运行,您的 Startup.cs Configure() 方法中是否包含以下代码?

app.UseSpa(spa =>
{
    // To learn more about options for serving an Angular SPA from ASP.NET Core,
    // see https://go.microsoft.com/fwlink/?linkid=864501

    spa.Options.SourcePath = "ClientApp";

    if (env.IsDevelopment())
    {
        spa.UseAngularCliServer(npmScript: "start");
    }
});

这就是 dotnet 告诉 angular cli 的方式,它告诉 npm 启动实时开发服务器,如果实时重新加载不起作用,这将是我首先查看的地方。

下一个位置是 package.json(我之前粘贴的)应该正确定义 ng start

如果这些都不能解决您的问题,请告诉我。

更新

以下句子错误;

The next place would be the package.json (which I pasted previously) should have ng start defined properly

应该阅读

.. the package.json should have a start property defined in the scripts section, which will call ng serve with your appropriate command line arguments (if any)