From 71b8b355a6284ada1cb03676e8d3c081791556c0 Mon Sep 17 00:00:00 2001 From: Kara Erickson Date: Thu, 25 Apr 2019 17:52:38 -0700 Subject: [PATCH] fix(ivy): remove debug utilities from ivy production builds (#30130) Prior to this commit, we were pulling DebugNode and DebugElement into production builds because BrowserModule automatically pulled in NgProbe and thus getDebugNode. In Ivy, this is not necessary because Ivy has its own set of debug utilities. We should use these existing tools instead of NgProbe. This commit adds an Ivy switch so we do not pull in NgProbe utilities when running with Ivy. This saves us ~8KB in prod builds. PR Close #30130 --- integration/_payload-limits.json | 2 +- packages/platform-browser/src/dom/debug/ng_probe.ts | 13 ++++++++++++- packages/platform-browser/src/platform-browser.ts | 2 ++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/integration/_payload-limits.json b/integration/_payload-limits.json index 29bff2e1fb..1fd3016633 100644 --- a/integration/_payload-limits.json +++ b/integration/_payload-limits.json @@ -21,7 +21,7 @@ "master": { "uncompressed": { "runtime": 1440, - "main": 157393, + "main": 149205, "polyfills": 43567 } } diff --git a/packages/platform-browser/src/dom/debug/ng_probe.ts b/packages/platform-browser/src/dom/debug/ng_probe.ts index fff61b86ad..d033a68145 100644 --- a/packages/platform-browser/src/dom/debug/ng_probe.ts +++ b/packages/platform-browser/src/dom/debug/ng_probe.ts @@ -36,10 +36,19 @@ function _ngProbeTokensToMap(tokens: core.NgProbeToken[]): {[name: string]: any} return tokens.reduce((prev: any, t: any) => (prev[t.name] = t.token, prev), {}); } +/** + * In Ivy, we don't support NgProbe because we have our own set of testing utilities + * with more robust functionality. + * + * We shouldn't bring in NgProbe because it prevents DebugNode and friends from + * tree-shaking properly. + */ +export const ELEMENT_PROBE_PROVIDERS__POST_R3__ = []; + /** * Providers which support debugging Angular applications (e.g. via `ng.probe`). */ -export const ELEMENT_PROBE_PROVIDERS: core.Provider[] = [ +export const ELEMENT_PROBE_PROVIDERS__PRE_R3__: core.Provider[] = [ { provide: core.APP_INITIALIZER, useFactory: _createNgProbe, @@ -49,3 +58,5 @@ export const ELEMENT_PROBE_PROVIDERS: core.Provider[] = [ multi: true, }, ]; + +export const ELEMENT_PROBE_PROVIDERS = ELEMENT_PROBE_PROVIDERS__PRE_R3__; diff --git a/packages/platform-browser/src/platform-browser.ts b/packages/platform-browser/src/platform-browser.ts index 3ba7be0a36..305313a529 100644 --- a/packages/platform-browser/src/platform-browser.ts +++ b/packages/platform-browser/src/platform-browser.ts @@ -18,3 +18,5 @@ export {DomSanitizer, SafeHtml, SafeResourceUrl, SafeScript, SafeStyle, SafeUrl, export * from './private_export'; export {VERSION} from './version'; +// This must be exported so it doesn't get tree-shaken away prematurely +export {ELEMENT_PROBE_PROVIDERS__POST_R3__ as ɵELEMENT_PROBE_PROVIDERS__POST_R3__} from './dom/debug/ng_probe';