]>
Commit | Line | Data |
---|---|---|
1 | import { enableProdMode, TRANSLATIONS, TRANSLATIONS_FORMAT } 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 | import { getDevLocale, isOnDevLocale } from '@app/shared/i18n/i18n-utils' | |
9 | import { buildFileLocale } from '../../shared' | |
10 | ||
11 | let providers: any[] = [] | |
12 | if (environment.production) { | |
13 | enableProdMode() | |
14 | } | |
15 | ||
16 | // Template translation, should be in the bootstrap step | |
17 | if (isOnDevLocale()) { | |
18 | const locale = buildFileLocale(getDevLocale()) | |
19 | const translations = require(`raw-loader!./locale/target/angular_${locale}.xml`) | |
20 | ||
21 | providers = [ | |
22 | { provide: TRANSLATIONS, useValue: translations }, | |
23 | { provide: TRANSLATIONS_FORMAT, useValue: 'xlf' } | |
24 | ] | |
25 | } | |
26 | ||
27 | const bootstrap = () => platformBrowserDynamic() | |
28 | .bootstrapModule(AppModule, { providers }) | |
29 | .then(bootstrapModule => { | |
30 | // TODO: Uncomment and remove unregistration when https://github.com/angular/angular/issues/21191 is fixed | |
31 | // TODO: Remove when https://github.com/angular/angular-cli/issues/8779 is fixed? | |
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 | ||
37 | if (navigator.serviceWorker && typeof navigator.serviceWorker.getRegistrations === 'function') { | |
38 | navigator.serviceWorker.getRegistrations() | |
39 | .then(registrations => { | |
40 | for (const registration of registrations) { | |
41 | registration.unregister() | |
42 | } | |
43 | }) | |
44 | } | |
45 | ||
46 | return bootstrapModule | |
47 | }) | |
48 | .catch(err => { | |
49 | console.error(err) | |
50 | return null | |
51 | }) | |
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 | } |