diff options
Diffstat (limited to 'client/src')
-rw-r--r-- | client/src/environments/environment.prod.ts | 1 | ||||
-rw-r--r-- | client/src/environments/environment.ts | 1 | ||||
-rw-r--r-- | client/src/hmr.ts | 16 | ||||
-rw-r--r-- | client/src/main.ts | 16 |
4 files changed, 32 insertions, 2 deletions
diff --git a/client/src/environments/environment.prod.ts b/client/src/environments/environment.prod.ts index c9f5a3b63..d5dfe5573 100644 --- a/client/src/environments/environment.prod.ts +++ b/client/src/environments/environment.prod.ts | |||
@@ -1,4 +1,5 @@ | |||
1 | export const environment = { | 1 | export const environment = { |
2 | production: true, | 2 | production: true, |
3 | hmr: false, | ||
3 | apiUrl: '' | 4 | apiUrl: '' |
4 | } | 5 | } |
diff --git a/client/src/environments/environment.ts b/client/src/environments/environment.ts index 43d788541..42b8baee8 100644 --- a/client/src/environments/environment.ts +++ b/client/src/environments/environment.ts | |||
@@ -5,5 +5,6 @@ | |||
5 | 5 | ||
6 | export const environment = { | 6 | export const environment = { |
7 | production: false, | 7 | production: false, |
8 | hmr: true, | ||
8 | apiUrl: 'http://localhost:9000' | 9 | apiUrl: 'http://localhost:9000' |
9 | } | 10 | } |
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 @@ | |||
1 | import { NgModuleRef, ApplicationRef } from '@angular/core' | ||
2 | import { createNewHosts } from '@angularclass/hmr' | ||
3 | |||
4 | export const hmrBootstrap = (module: any, bootstrap: () => Promise<NgModuleRef<any>>) => { | ||
5 | let ngModule: NgModuleRef<any> | ||
6 | module.hot.accept() | ||
7 | bootstrap() | ||
8 | .then(mod => ngModule = mod) | ||
9 | module.hot.dispose(() => { | ||
10 | const appRef: ApplicationRef = ngModule.injector.get(ApplicationRef) | ||
11 | const elements = appRef.components.map(c => c.location.nativeElement) | ||
12 | const makeVisible = createNewHosts(elements) | ||
13 | ngModule.destroy() | ||
14 | makeVisible() | ||
15 | }) | ||
16 | } | ||
diff --git a/client/src/main.ts b/client/src/main.ts index f3825fe50..b02b6830f 100644 --- a/client/src/main.ts +++ b/client/src/main.ts | |||
@@ -4,10 +4,22 @@ import { platformBrowserDynamic } from '@angular/platform-browser-dynamic' | |||
4 | import { AppModule } from './app/app.module' | 4 | import { AppModule } from './app/app.module' |
5 | import { environment } from './environments/environment' | 5 | import { environment } from './environments/environment' |
6 | 6 | ||
7 | import { hmrBootstrap } from './hmr' | ||
8 | |||
7 | if (environment.production) { | 9 | if (environment.production) { |
8 | enableProdMode() | 10 | enableProdMode() |
9 | } | 11 | } |
10 | 12 | ||
11 | platformBrowserDynamic() | 13 | const bootstrap = () => platformBrowserDynamic() |
12 | .bootstrapModule(AppModule) | 14 | .bootstrapModule(AppModule) |
13 | .catch(err => console.log(err)) | 15 | |
16 | if (environment.hmr) { | ||
17 | if (module[ 'hot' ]) { | ||
18 | hmrBootstrap(module, bootstrap) | ||
19 | } else { | ||
20 | console.error('HMR is not enabled for webpack-dev-server!') | ||
21 | console.log('Are you using the --hmr flag for ng serve?') | ||
22 | } | ||
23 | } else { | ||
24 | bootstrap() | ||
25 | } | ||