1 | import { NgModuleRef, ApplicationRef } from '@angular/core';
|
2 | import { createNewHosts } from '@angularclass/hmr';
|
3 |
|
4 | export const HMR_BOOTSTRAP = async (module: any, bootstrap: () => Promise<NgModuleRef<any>>) => {
|
5 | let ngModule: NgModuleRef<any>;
|
6 | module.hot.accept();
|
7 | bootstrap()
|
8 | .then((mod) => ngModule = mod)
|
9 | .catch();
|
10 | module.hot.dispose(() => {
|
11 | const appRef: ApplicationRef = ngModule.injector.get(ApplicationRef);
|
12 | const elements = appRef.components.map((c) => c.location.nativeElement);
|
13 | const makeVisible = createNewHosts(elements);
|
14 | ngModule.destroy();
|
15 | makeVisible();
|
16 | });
|
17 | };
|