65

(即使使用 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
4

2 回答 2

4

angular-cli wiki 页面已弃用:https ://github.com/angular/angular-cli/issues/14053

目前不支持 Angular-HMR + 惰性路由:https ://github.com/PatrickJS/angular-hmr/issues/76

对于一个有效且重要的解决方案,请查看https://github.com/wags1999/angular-hmr-lazy-components

于 2019-04-09T06:17:12.050 回答
-2

就像警告人们遇到这个问题一样。我更新angular-clihmr停止工作。它显示的只是空白页面。

在职的:

"@angular-devkit/build-angular": "0.10.2",
"@angular/cli": "^7.0.3",
"@angular/compiler-cli": "^7.0.3",

不工作:

"@angular-devkit/build-angular": "~0.6.8",
"@angular/cli": "~7.0.6",
"@angular/compiler-cli": "^7.1.0",
于 2019-05-02T15:00:32.957 回答