import { NgModuleRef, ApplicationRef } from '@angular/core'; import { createNewHosts } from '@angularclass/hmr'; export const HMR_BOOTSTRAP = async (module: any, bootstrap: () => Promise>) => { let ngModule: NgModuleRef; module.hot.accept(); bootstrap() .then((mod) => ngModule = mod) .catch(); module.hot.dispose(() => { const appRef: ApplicationRef = ngModule.injector.get(ApplicationRef); const elements = appRef.components.map((c) => c.location.nativeElement); const makeVisible = createNewHosts(elements); ngModule.destroy(); makeVisible(); }); };