(即使使用 Angular 7 也确认了一个问题)。让我们解决这个问题!
我正在使用此处设置的 HMR:https ://github.com/angular/angular-cli/wiki/stories-configure-hmr来自全新ng new
版本。
如果我更改任何组件并使其延迟加载,角度 HMR 将热重新加载所有内容,从而使页面同步变慢。
我知道这一点,因为它默认设置console.log
为正在重新加载的每个模块,并且当我使用惰性路由时,它会记录所有内容。但是当我将该组件更改为非延迟加载时,它只会记录一些小组件。
因此,当我使用 HMR 和惰性路由时,我的应用程序需要几秒钟才能刷新。这很烦人。
有没有办法解决?
(延迟加载路线是通过这样的事情来完成的)
// Main homepage
{
path: '',
loadChildren: './public/home/home.module#HomeModule'
},
// ...
(只是一个例子来说明我正在以正确的方式延迟加载)
这里有一些日志显示当我延迟加载时会发生什么home.component.ts
// Everything here is normal, great!
[HMR] - ../../../../../src/app/public/home/home.component.html
log.js:23 [HMR] - ../../../../../src/app/public/home/home.component.ts
log.js:23 [HMR] - ../../../../../src/app/public/home/home.module.ts
log.js:23 [HMR] - ../../../../../src/app/public/home/home.routing.ts
// Everything below here is NOT normal, bad! All this is extra. These are my modules, yes, but all this needs to be loaded again?
log.js:23 [HMR] - ../../../../../src/$$_lazy_route_resource lazy recursive
log.js:23 [HMR] - ../../../core/esm5/core.js
log.js:23 [HMR] - ../../../platform-browser-dynamic/esm5/platform-browser-dynamic.js
log.js:23 [HMR] - ../../../common/esm5/common.js
log.js:23 [HMR] - ../../../platform-browser/esm5/platform-browser.js
log.js:23 [HMR] - ../../../router/esm5/router.js
log.js:23 [HMR] - ../../../../../src/app/shared/shared.module.ts
log.js:23 [HMR] - ../../../common/esm5/http.js
log.js:23 [HMR] - ../../../../../src/app/features/proxy-http-interceptor/proxy-http-interceptor.ts
log.js:23 [HMR] - ../../../../../src/app/shared/unauthorized-http-interceptor.ts
log.js:23 [HMR] - ../../../../../src/app/features/auth/auth.service.ts
log.js:23 [HMR] - ../../../../../src/app/features/user/user.service.ts
log.js:23 [HMR] - ../../../../@auth0/angular-jwt/index.js
log.js:23 [HMR] - ../../../../@auth0/angular-jwt/src/jwt.interceptor.js
log.js:23 [HMR] - ../../../../@auth0/angular-jwt/src/jwthelper.service.js
log.js:23 [HMR] - ../../../../@auth0/angular-jwt/src/jwtoptions.token.js
log.js:23 [HMR] - ../../../../../src/app/shared/container.directive.ts
log.js:23 [HMR] - ../../../flex-layout/esm5/flex-layout.es5.js
...
...
A ton more logging