Skip to content

Instantly share code, notes, and snippets.

@Dok11
Last active July 9, 2020 08:08
Show Gist options
  • Save Dok11/f76a21d63b6892a204be6f0e57d5c48b to your computer and use it in GitHub Desktop.
Save Dok11/f76a21d63b6892a204be6f0e57d5c48b to your computer and use it in GitHub Desktop.
Angular debug tools (with HMR settings)
import {ApplicationRef, enableProdMode} from '@angular/core';
import {enableDebugTools} from '@angular/platform-browser';
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import {AppModule} from './app/app.module';
import {environment} from './environments/environment';
import {hmrBootstrap} from './hmr';
if (environment.production) {
enableProdMode();
}
const bootstrap = () => platformBrowserDynamic().bootstrapModule(AppModule).then((module) => {
if (!environment.production) {
// ng.profiler.timeChangeDetection({record: true})
const applicationRef = module.injector.get(ApplicationRef);
const appComponent = applicationRef.components[0];
enableDebugTools(appComponent);
}
return module;
});
if (environment.hmr) {
if (module[ 'hot' ]) {
hmrBootstrap(module, bootstrap);
} else {
console.error('HMR is not enabled for webpack-dev-server!');
console.log('Are you using the --hmr flag for ng serve?');
}
} else {
bootstrap();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment