javascript 在 ng serve 和更新后,Angular 4 CLI 太慢
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45818811/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Angular 4 CLI too slow after ng serve and when updating
提问by Voltaire John Secondes Biton
I have pasted a screenshot after i run ng serve. it is on 34946 ms. it is pretty slow and it is hurting the performance of our team. When we also update our code, it takes too long to reload the page.
我在运行 ng serve 后粘贴了屏幕截图。它是 34946 毫秒。它非常缓慢,并且正在损害我们团队的表现。当我们也更新我们的代码时,重新加载页面需要很长时间。
My version of angular is Angular CLI version (1.2.7)
我的 angular 版本是 Angular CLI 版本 (1.2.7)
Is this an issue or is this normal in Angular CLI?
这是一个问题还是 Angular CLI 中的正常现象?
We already have around 40 components on the project but i am not sure if it affects the loading performance.
我们项目中已经有大约 40 个组件,但我不确定它是否会影响加载性能。
Here is the specs of my PC just incase.
这是我的 PC 的规格,以防万一。
采纳答案by Voltaire John Secondes Biton
i solved my problem. What happened is that our components and other resources are all imported in app.module.ts. Because of this, the page loads all the resources every time the page loads. My solution was to apply Lazy Loadingto load only those resources that are specific to the routes that i am accessing and it did fix up the loading issue.
我解决了我的问题。发生的事情是我们的组件和其他资源都在app.module.ts 中导入。因此,每次页面加载时,页面都会加载所有资源。我的解决方案是应用延迟加载只加载那些特定于我正在访问的路由的资源,它确实解决了加载问题。
回答by kuncevic.dev
You have this problem is because your dev PC have not enough memory to handle the build as nodejsis consuming a lot of memory when you run expensive npmtasks. And the bigger your project the more memory is required to complete the task. The problem can get even worse if you want to run ng serve+ ng t+ ng whatewerat the same time.
您遇到这个问题是因为您的开发 PC 没有足够的内存来处理构建,因为当您运行昂贵的npm任务时,nodejs会消耗大量内存。项目越大,完成任务所需的内存就越多。如果你想运行的问题可以变得更糟ng serve+ ng t+ng whatewer在同一时间。
Check the Task manager-> Perfomrmance tabthen run ng serveand you will see what I am talking about.
检查任务管理器->性能选项卡,然后运行ng serve,您将看到我在说什么。
I had struggled by the same problem until I put another 8gb RAM in my dev PC.
我一直在为同样的问题而苦苦挣扎,直到我在我的开发 PC 中再放了一个 8GB RAM。
So yes it is normal.
所以是的,这是正常的。
回答by Bienfait Rukundo
you have to update your Node.js to the last version check to thin link node.js web siteto update your Node.js
您必须将您的 Node.js 更新到最新版本 检查到细链接node.js 网站以更新您的 Node.js


