From 77d07d690968a9631fc0c8bafbaebd27a5ebaab6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 12 Dec 2017 14:45:42 +0100 Subject: Add hmr --- client/src/hmr.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 client/src/hmr.ts (limited to 'client/src/hmr.ts') diff --git a/client/src/hmr.ts b/client/src/hmr.ts new file mode 100644 index 000000000..4d707a250 --- /dev/null +++ b/client/src/hmr.ts @@ -0,0 +1,16 @@ +import { NgModuleRef, ApplicationRef } from '@angular/core' +import { createNewHosts } from '@angularclass/hmr' + +export const hmrBootstrap = (module: any, bootstrap: () => Promise>) => { + let ngModule: NgModuleRef + module.hot.accept() + bootstrap() + .then(mod => ngModule = mod) + 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() + }) +} -- cgit v1.2.3