From b7a2d0da200cec736125238ac9533eb535ecd8ed Mon Sep 17 00:00:00 2001 From: arturovt Date: Wed, 17 Feb 2021 00:16:13 +0200 Subject: [PATCH] perf(core): use `ngDevMode` to tree-shake warning (#40876) This commit adds `ngDevMode` guard to show the warning only in dev mode (similar to how things work in other parts of Ivy runtime code). The `ngDevMode` flag helps to tree-shake the warning from production builds (in dev mode everything will work as it works right now) to decrease production bundle size. PR Close #40876 --- goldens/size-tracking/aio-payloads.json | 2 +- packages/core/src/application_module.ts | 3 +-- packages/core/src/application_ref.ts | 10 ++++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/goldens/size-tracking/aio-payloads.json b/goldens/size-tracking/aio-payloads.json index d42dee64fe..5765876886 100755 --- a/goldens/size-tracking/aio-payloads.json +++ b/goldens/size-tracking/aio-payloads.json @@ -12,7 +12,7 @@ "master": { "uncompressed": { "runtime-es2015": 3033, - "main-es2015": 448036, + "main-es2015": 447894, "polyfills-es2015": 52493 } } diff --git a/packages/core/src/application_module.ts b/packages/core/src/application_module.ts index b5eedcede5..1079d19812 100644 --- a/packages/core/src/application_module.ts +++ b/packages/core/src/application_module.ts @@ -10,7 +10,6 @@ import {APP_INITIALIZER, ApplicationInitStatus} from './application_init'; import {ApplicationRef} from './application_ref'; import {APP_ID_RANDOM_PROVIDER} from './application_tokens'; import {defaultIterableDiffers, defaultKeyValueDiffers, IterableDiffers, KeyValueDiffers} from './change_detection/change_detection'; -import {Console} from './console'; import {Injector, StaticProvider} from './di'; import {Inject, Optional, SkipSelf} from './di/metadata'; import {ErrorHandler} from './error_handler'; @@ -78,7 +77,7 @@ export const APPLICATION_MODULE_PROVIDERS: StaticProvider[] = [ { provide: ApplicationRef, useClass: ApplicationRef, - deps: [NgZone, Console, Injector, ErrorHandler, ComponentFactoryResolver, ApplicationInitStatus] + deps: [NgZone, Injector, ErrorHandler, ComponentFactoryResolver, ApplicationInitStatus] }, {provide: SCHEDULER, deps: [NgZone], useFactory: zoneSchedulerFactory}, { diff --git a/packages/core/src/application_ref.ts b/packages/core/src/application_ref.ts index 5b5b1cf5e3..40d6bf6591 100644 --- a/packages/core/src/application_ref.ts +++ b/packages/core/src/application_ref.ts @@ -621,8 +621,7 @@ export class ApplicationRef { /** @internal */ constructor( - private _zone: NgZone, private _console: Console, private _injector: Injector, - private _exceptionHandler: ErrorHandler, + private _zone: NgZone, private _injector: Injector, private _exceptionHandler: ErrorHandler, private _componentFactoryResolver: ComponentFactoryResolver, private _initStatus: ApplicationInitStatus) { this._onMicrotaskEmptySubscription = this._zone.onMicrotaskEmpty.subscribe({ @@ -734,8 +733,11 @@ export class ApplicationRef { }); this._loadComponent(compRef); - if (isDevMode()) { - this._console.log( + // Note that we have still left the `isDevMode()` condition in order to avoid + // creating a breaking change for projects that still use the View Engine. + if ((typeof ngDevMode === 'undefined' || ngDevMode) && isDevMode()) { + const _console = this._injector.get(Console); + _console.log( `Angular is running in development mode. Call enableProdMode() to enable production mode.`); } return compRef;