]>
Commit | Line | Data |
---|---|---|
1 | import { enableProdMode } from '@angular/core' | |
2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic' | |
3 | ||
4 | import { AppModule } from './app/app.module' | |
5 | import { environment } from './environments/environment' | |
6 | ||
7 | import { hmrBootstrap } from './hmr' | |
8 | ||
9 | if (environment.production) { | |
10 | enableProdMode() | |
11 | } | |
12 | ||
13 | const bootstrap = () => platformBrowserDynamic() | |
14 | .bootstrapModule(AppModule) | |
15 | .then(bootstrapModule => { | |
16 | // TODO: Uncomment and remove unregistration when https://github.com/angular/angular/issues/21191 is fixed | |
17 | // TODO: Remove when https://github.com/angular/angular-cli/issues/8779 is fixed? | |
18 | // if ('serviceWorker' in navigator && environment.production) { | |
19 | // navigator.serviceWorker.register('/ngsw-worker.js') | |
20 | // .catch(err => console.error('Cannot register service worker.', err)) | |
21 | // } | |
22 | ||
23 | if (navigator.serviceWorker && typeof navigator.serviceWorker.getRegistrations === 'function') { | |
24 | navigator.serviceWorker.getRegistrations() | |
25 | .then(registrations => { | |
26 | for (const registration of registrations) { | |
27 | registration.unregister() | |
28 | } | |
29 | }) | |
30 | } | |
31 | ||
32 | return bootstrapModule | |
33 | }) | |
34 | .catch(err => { | |
35 | console.error(err) | |
36 | return null | |
37 | }) | |
38 | ||
39 | if (environment.hmr) { | |
40 | if (module[ 'hot' ]) { | |
41 | hmrBootstrap(module, bootstrap) | |
42 | } else { | |
43 | console.error('HMR is not enabled for webpack-dev-server!') | |
44 | console.log('Are you using the --hmr flag for ng serve?') | |
45 | } | |
46 | } else { | |
47 | bootstrap() | |
48 | } |