Angular 4 CLI too slow after ng serve and when upd

2019-02-17 12:40发布

问题:

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.

My version of angular is Angular CLI version (1.2.7)

Is this an issue or is this normal in Angular CLI?

We already have around 40 components on the project but i am not sure if it affects the loading performance.

Here is the specs of my PC just incase.

回答1:

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 Loading to load only those resources that are specific to the routes that i am accessing and it did fix up the loading issue.



回答2:

You have this problem is because your dev PC have not enough memory to handle the build as nodejs is consuming a lot of memory when you run expensive npm tasks. 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 whatewer at the same time.

Check the Task manager -> Perfomrmance tab then run ng serve and you will see what I am talking about.

I had struggled by the same problem until I put another 8gb RAM in my dev PC.

So yes it is normal.



回答3:

you have to update your Node.js to the last version check to thin link node.js web site to update your Node.js