]>
Commit | Line | Data |
---|---|---|
e309822b | 1 | import { enableProdMode, TRANSLATIONS, TRANSLATIONS_FORMAT } from '@angular/core' |
b6827820 | 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic' |
63c4db6d | 3 | |
b6827820 C |
4 | import { AppModule } from './app/app.module' |
5 | import { environment } from './environments/environment' | |
63c4db6d | 6 | |
77d07d69 | 7 | import { hmrBootstrap } from './hmr' |
74b7c6d4 | 8 | import { getDevLocale, isOnDevLocale } from '@app/shared/i18n/i18n-utils' |
c0ffdd09 | 9 | import { buildFileLocale } from '../../shared' |
77d07d69 | 10 | |
244b4ae3 | 11 | let providers: any[] = [] |
63c4db6d | 12 | if (environment.production) { |
b6827820 | 13 | enableProdMode() |
63c4db6d C |
14 | } |
15 | ||
74b7c6d4 C |
16 | // Template translation, should be in the bootstrap step |
17 | if (isOnDevLocale()) { | |
c0ffdd09 | 18 | const locale = buildFileLocale(getDevLocale()) |
350131cb | 19 | const translations = require(`raw-loader!./locale/angular.${locale}.xlf`) |
e309822b C |
20 | |
21 | providers = [ | |
22 | { provide: TRANSLATIONS, useValue: translations }, | |
23 | { provide: TRANSLATIONS_FORMAT, useValue: 'xlf' } | |
24 | ] | |
25 | } | |
26 | ||
77d07d69 | 27 | const bootstrap = () => platformBrowserDynamic() |
e309822b | 28 | .bootstrapModule(AppModule, { providers }) |
78967fca | 29 | .then(bootstrapModule => { |
fed95155 | 30 | // TODO: Uncomment and remove unregistration when https://github.com/angular/angular/issues/21191 is fixed |
78967fca | 31 | // TODO: Remove when https://github.com/angular/angular-cli/issues/8779 is fixed? |
fed95155 C |
32 | // if ('serviceWorker' in navigator && environment.production) { |
33 | // navigator.serviceWorker.register('/ngsw-worker.js') | |
34 | // .catch(err => console.error('Cannot register service worker.', err)) | |
35 | // } | |
36 | ||
c7ca4c8b | 37 | if (navigator.serviceWorker && typeof navigator.serviceWorker.getRegistrations === 'function') { |
73e09f27 C |
38 | navigator.serviceWorker.getRegistrations() |
39 | .then(registrations => { | |
40 | for (const registration of registrations) { | |
41 | registration.unregister() | |
42 | } | |
43 | }) | |
44 | } | |
78967fca C |
45 | |
46 | return bootstrapModule | |
47 | }) | |
48 | .catch(err => { | |
49 | console.error(err) | |
50 | return null | |
51 | }) | |
77d07d69 C |
52 | |
53 | if (environment.hmr) { | |
54 | if (module[ 'hot' ]) { | |
55 | hmrBootstrap(module, bootstrap) | |
56 | } else { | |
57 | console.error('HMR is not enabled for webpack-dev-server!') | |
58 | console.log('Are you using the --hmr flag for ng serve?') | |
59 | } | |
60 | } else { | |
61 | bootstrap() | |
62 | } |