forked from tensorflow/tensorboard
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate to Angular's app_bundle for bundling. (tensorflow#6049)
The upcoming upgrade to Angular 13+ introduces a number of bundling-related problems for our tests and applications. Angular has developed some internal tooling to help resolve these problems. This change uses Angular's internal app_bundle() macro to allow us to continue to bundle Angular13+-compatible apps. Note: app_bundle() is Angular-internal and not supported for external use. We use it at our own risk. Googlers, see the following documents for background and justification: http://go/angular-bazel-problems, http://go/tb-oss-bundling. Note: We migrated our tests to use the similar spec_bundle() in tensorflow#6036. Our usage of app_bundle() is largely guided/inspired by the usage in the angular/components repo. This is the version at HEAD as of early November: https://github.com/angular/components/blob/871f8f231a7a86a7a0778e345f4d517109c9a357/tools/defaults.bzl We will now have two bundling targets: tf_js_binary(), which remains unchanged; and tf_ng_prod_js_binary(), which is new and delegates to app_bundle(). tf_ng_prod_js_binary() is, in practice, only used for one bundle: The production Angular bundle at //tensorboard/webapp:tb_webapp_binary. All other bundles, including our dev Angular bundle, continue to use tf_js_binary(). Googlers, see detailed reasoning in http://go/tb-oss-bundling. Highlights. 1. Run the following commands to install additional Angular build tooling and terser and then clean the environment: * `yarn add @angular-devkit/[email protected] @bazel/[email protected] --dev` * `yarn run yarn-deduplicate` * `rm -rf node_modules; bazel clean --expunge; yarn;` 2. Patch the Angular build tooling to suit our code base: * Patch the esbuild config to point to old paths for tools in @angular/compiler-cli. When we upgrade @angular/compiler-cli to Angular 13+ then we will be able to delete this portion of the patch. * Patch some of the babel-based optimization code to remove one particular plugin that is too aggressive in removing symbols. It is incompatible with the TensorBoard code base. 3. Add tf_ng_prod_js_binary, which delegates to app_bundle(), and use it for //tensorboard/webapp:tb_webapp_binary. Impact on "//tensorboard" build: * "//tensorboard/webapp:tb_webapp_binary" bundle size: * Before: 5,440,612 bytes * After: 4,790,003 * "//tensorboard/webapp:tb_webapp_binary" bundle time: * Before: 1 or 2 seconds. * After: ~20 seconds. * This is an ok tradeoff since we continue to encourage engineers to use the faster "//tensorboard:dev" and its dev bundle for local development. Impact on "//tensorboard:dev" target: * No impact on either bundle size or bundle time since we continue to use tf_js_binary(). It remains big but fast. * Note that when we update to Angular 13 we will have to change "//tensorboard:dev" to use Angular JIT compilation. Initial observations show that the JIT compilation does not meaningfully slow down app load or interaction times.
- Loading branch information
Showing
6 changed files
with
1,581 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
patches/@angular+build-tooling+0.0.0-7d103b83a07f132629592fc9918ce17d42a5e382.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
diff --git a/node_modules/@angular/build-tooling/bazel/app-bundling/esbuild.config-tmpl.mjs b/node_modules/@angular/build-tooling/bazel/app-bundling/esbuild.config-tmpl.mjs | ||
index 618bbc5..05a112f 100755 | ||
--- a/node_modules/@angular/build-tooling/bazel/app-bundling/esbuild.config-tmpl.mjs | ||
+++ b/node_modules/@angular/build-tooling/bazel/app-bundling/esbuild.config-tmpl.mjs | ||
@@ -9,9 +9,18 @@ | ||
import * as path from 'path'; | ||
|
||
import {createEsbuildAngularOptimizePlugin} from '@angular/build-tooling/shared-scripts/angular-optimization/esbuild-plugin.mjs'; | ||
-import {createEs2015LinkerPlugin} from '@angular/compiler-cli/linker/babel'; | ||
-import {ConsoleLogger, NodeJSFileSystem, LogLevel} from '@angular/compiler-cli'; | ||
-import {GLOBAL_DEFS_FOR_TERSER_WITH_AOT} from '@angular/compiler-cli/private/tooling'; | ||
+// For TensorBoard: Patch the esbuild config template so that imports are | ||
+// grabbed from the correct places. This is just the consequence of some | ||
+// skew using pre-13.X @angular/compiler-cli binaries. This should be resolved | ||
+// once we upgrade to Angular 13+. | ||
+//import {createEs2015LinkerPlugin} from '@angular/compiler-cli/linker/babel'; | ||
+import {createEs2015LinkerPlugin} from '@angular/compiler-cli/linker/babel/index.js'; | ||
+//import {ConsoleLogger, NodeJSFileSystem, LogLevel} from '@angular/compiler-cli'; | ||
+import {NodeJSFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system/src/node_js_file_system.js'; | ||
+import {LogLevel} from '@angular/compiler-cli/src/ngtsc/logging/index.js'; | ||
+import {ConsoleLogger} from '@angular/compiler-cli/src/ngtsc/logging/src/console_logger.js'; | ||
+//import {GLOBAL_DEFS_FOR_TERSER_WITH_AOT} from '@angular/compiler-cli/private/tooling'; | ||
+import {GLOBAL_DEFS_FOR_TERSER_WITH_AOT} from '@angular/compiler-cli/src/tooling.js'; | ||
|
||
/** Root path pointing to the app bundle source entry-point file. */ | ||
const entryPointSourceRootPath = path.normalize(`TMPL_ENTRY_POINT_ROOTPATH`); | ||
diff --git a/node_modules/@angular/build-tooling/shared-scripts/angular-optimization/esbuild-plugin.mjs b/node_modules/@angular/build-tooling/shared-scripts/angular-optimization/esbuild-plugin.mjs | ||
index 57cd2b9..2e5eaf1 100755 | ||
--- a/node_modules/@angular/build-tooling/shared-scripts/angular-optimization/esbuild-plugin.mjs | ||
+++ b/node_modules/@angular/build-tooling/shared-scripts/angular-optimization/esbuild-plugin.mjs | ||
@@ -43,9 +43,12 @@ export function createEsbuildAngularOptimizePlugin( | ||
|
||
// If the current file is denoted as explicit side effect free, add the pure | ||
// top-level functions optimization plugin for this file. | ||
- if (isSideEffectFreeFn !== null && isSideEffectFreeFn(args.path)) { | ||
- plugins.push(pureToplevelFunctionsPlugin); | ||
- } | ||
+ // For TensorBoard: This plugin aggressively culls symbols in a way that | ||
+ // is incompatible with TensorBoard source. Remove it. The binary is | ||
+ // bigger than it otherwise could be but the bundle also happens faster. | ||
+ //if (isSideEffectFreeFn !== null && isSideEffectFreeFn(args.path)) { | ||
+ // plugins.push(pureToplevelFunctionsPlugin); | ||
+ //} | ||
|
||
const {code} = await babel.transformAsync(content, { | ||
filename: filePath, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.