Angular6 实时重新加载在Angular 6更新后不再工作
解决方法实际上是删除ClientApp/dist文件夹。但每次我“发布”时,我都必须再次删除它 你知道怎么修吗 My Startup.cs使用此文件夹Angular6 实时重新加载在Angular 6更新后不再工作,angular6,asp.net-core-2.1,Angular6,Asp.net Core 2.1,解决方法实际上是删除ClientApp/dist文件夹。但每次我“发布”时,我都必须再次删除它 你知道怎么修吗 My 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(
// 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新的角度模板
并遵循本指南:
并从ClientApp/package.json
"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升级到了angular 6,dotnet core和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启动live development服务器,如果live reload不起作用,这将是我首先查看的地方
下一个地方是包。json
(我之前粘贴过)应该正确定义ngstart
如果这些都不能解决你的问题,请告诉我
更新
下列句子中的错误
下一个地方是包。json
(我之前粘贴过)应该正确定义ngstart
应该读
。。package.json
应该在scripts
部分中定义一个start
属性,该属性将使用适当的命令行参数(如果有)调用ng serve
你能再扩大一点吗?您是在使用来自dotnet new angular
的项目模板还是什么?是的,我将angular 5更新为6Open,然后修改任何HTML,不会触发实时重新加载。似乎发生了重新编译,但未在浏览器中更新HTML。注意:在打开Angular Live Development服务器时将进行实时重新加载,但后端不工作。这就是为什么我认为这是一个dotnet设置问题。这就是为什么我不使用dotnet模板它被称为ng serve
而不是ng start
)(除非您的意思是npm start
)谢谢,帖子确实需要更新,但是ng-serve
或ng-start
在帖子上下文中都不正确。请参阅更新。