Angular 12 'ng serve' 构建应用程序的速度很慢,几乎就像生产构建一样 [英] Angular 12 'ng serve' builds apps slowly, almost like production builds

查看:30
本文介绍了Angular 12 'ng serve' 构建应用程序的速度很慢,几乎就像生产构建一样的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚将一个应用程序从 Angular 11.2.7 迁移到了 Angular 12.一切都运行良好,除了在我开发和使用ng serve"时,重建时间现在要慢得多,以至于现在令人沮丧.

I've just migrated an app from Angular 11.2.7 to Angular 12. Everything runs fine, except that when I am developing and using 'ng serve', rebuild times are much, much slower now, to the point where it's frustrating.

我使用的是 M1 iMac,使用节点 16.1.0,物有所值.

I'm on an M1 iMac, using node 16.1.0, for what it's worth.

在我转向 Angular 12 之前,机器在开发重建(亚秒级)时闪电般快速.现在如果我只更改一行代码,即使我只更改控制台日志中的一个字母,构建时间也是 23 秒,其中大约 22 秒用于阶段:密封".

The machine was lightning fast at dev rebuilds (sub-second) before I moved to Angular 12. Now if I change just one line of code, even if I just change one letter in a console log, build times are 23 seconds, roughly 22 seconds of which are taken up with "phase: sealing".

我还注意到现在一切都从缩小的main.js"运行.即使在 ng 服务时.我似乎记得版本 11 没有这样做,而是在开发过程中运行了单个未缩小的组件.也就是说,ng serve 现在似乎正在做一些类似完整的生产构建每次我更改任何内容的事情.我认为这是缓慢的根本原因,但我不确定.

I've also noticed that everything now runs from a minified 'main.js" even when ng serving. I seem to recall version 11 didn't do that, but ran individual un-minified components during dev. Which is to say, ng serve now seems to be doing something like full a production build every time I change anything. I think that's the root cause of the slowness, but I'm not sure.

所以...

我还应该在 Angular 12 中使用 'ng serve' 进行开发吗?

Should I still be using 'ng serve' for development in Angular 12?

迁移时是否有需要设置的选项,也许是关闭完全缩小重建,以保持旧的构建速度?

Is there an option that needs to be set when you migrate, perhaps to turn off full minified rebuilds, to maintain the old build speed?

无论如何,这个密封阶段"是什么?对我来说,这听起来像是一个生产构建术语!

What is this 'sealing phase', anyway? It sounds like a production build term to me!

谢谢

约翰

推荐答案

angular cli 更新为 v12,使开发环境更像生产环境.

The angular cli got updated with v12 to have the development environment be more like production.

或者他们喜欢这样称呼它:

Or as they like to call it:

这些更改的目的是降低配置复杂性并支持新的默认生产版本".倡议.

The aim of these changes is to reduce the configuration complexity and support the new "production builds by default" initiative.

根据他们的更改判断,您应该更新您的 angular.json 并更新 projects.{PROJECT_NAME}.architect.build.defaultConfiguration 路径:

Judging by what they've changed, you should update your angular.json and update the projects.{PROJECT_NAME}.architect.build.defaultConfiguration path:

"defaultConfiguration": "development"

阅读更多此处

如果您没有使用 ng update 命令,而是使用 npm 手动更新,则需要运行迁移.具体来说,材料样式发生了一些变化,如果不迁移,可能会导致构建时间过长.要触发这些迁移,请运行:

If you did not use the ng update command, but manually updated using npm, you need to run migrations. Specifically the material styling had some changes which can cause long build times if not migrated. To trigger these migrations run:

ng update @angular/cli --migrate-only --from 11 --to 12

这篇关于Angular 12 'ng serve' 构建应用程序的速度很慢,几乎就像生产构建一样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆