mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
ad9ba9a95f
The Angular build system recently introduced an opt-in chunk optimizer for application builds. This is now enabled for adev production builds. It reduces the initial chunk count from 14 to 1 JavaScript file. While the raw initial total file size does increase by 0.75% (7.3kB), the total estimated transfer size decreases by 8% (17.8kB). Not only does this reduce the amount of data that must be sent over the network but it also reduces the amount of HTTP requests that must be made by the browser. While the injected HTML module preloads mitigate request cascades, not needing to make the requests is even better. PR Close #56830
188 lines
4.7 KiB
Python
188 lines
4.7 KiB
Python
load("@npm//@angular/build-tooling/bazel/remote-execution:index.bzl", "ENABLE_NETWORK")
|
|
load("@npm//@angular/build-tooling/bazel/http-server:index.bzl", "http_server")
|
|
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
|
|
load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin")
|
|
load("@npm//@angular-devkit/architect-cli:index.bzl", "architect", "architect_test")
|
|
load("@bazel_skylib//lib:collections.bzl", "collections")
|
|
load("//adev/tools/local_deps:index.bzl", "ensure_local_package_deps", "link_local_packages")
|
|
|
|
package(default_visibility = ["//visibility:public"])
|
|
|
|
exports_files([
|
|
"tsconfig.json",
|
|
])
|
|
|
|
# All source and configuration files required to build the docs app
|
|
APPLICATION_FILES = [
|
|
"angular.json",
|
|
"tsconfig.app.json",
|
|
"tsconfig.json",
|
|
"tsconfig.worker.json",
|
|
] + glob(
|
|
["src/**/*"],
|
|
exclude = [
|
|
"src/**/*.spec.ts",
|
|
],
|
|
)
|
|
|
|
TEST_FILES = APPLICATION_FILES + [
|
|
"karma.conf.js",
|
|
"test-main.ts",
|
|
"tsconfig.spec.json",
|
|
] + glob(
|
|
["src/**/*.spec.ts"],
|
|
)
|
|
|
|
APPLICATION_ASSETS = [
|
|
"//adev/src/assets/images",
|
|
"//adev/src/assets/textures",
|
|
"//adev/src/assets/previews",
|
|
"//adev/src/assets:tutorials",
|
|
"//adev/src/assets/icons",
|
|
"//adev/src/assets:api",
|
|
"//adev/src/assets:content",
|
|
]
|
|
|
|
APPLICATION_DEPS = [
|
|
"@npm//@angular/docs",
|
|
"@npm//@angular/build",
|
|
"@npm//@angular-devkit/build-angular",
|
|
"@npm//@angular/animations",
|
|
"@npm//@angular/cdk",
|
|
"@npm//@angular/common",
|
|
"@npm//@angular/compiler",
|
|
"@npm//@angular/compiler-cli",
|
|
"@npm//@angular/core",
|
|
"@npm//@angular/forms",
|
|
"@npm//@angular/material",
|
|
"@npm//@angular/platform-browser",
|
|
"@npm//@angular/platform-server",
|
|
"@npm//@angular/router",
|
|
"@npm//gsap",
|
|
"@npm//marked",
|
|
"@npm//ngx-progressbar",
|
|
"@npm//ogl",
|
|
"@npm//rxjs",
|
|
"@npm//typescript",
|
|
"@npm//@typescript/vfs",
|
|
"@npm//@codemirror/state",
|
|
"@npm//@codemirror/view",
|
|
"@npm//@codemirror/language",
|
|
"@npm//@codemirror/commands",
|
|
"@npm//@codemirror/search",
|
|
"@npm//@codemirror/autocomplete",
|
|
"@npm//@codemirror/lint",
|
|
"@npm//@codemirror/lang-html",
|
|
"@npm//@codemirror/lang-angular",
|
|
"@npm//@codemirror/lang-css",
|
|
"@npm//@codemirror/lang-sass",
|
|
"@npm//@codemirror/lang-javascript",
|
|
"@npm//@lezer/highlight",
|
|
"@npm//@lezer/javascript",
|
|
"@npm//@lezer/common",
|
|
"@npm//@stackblitz/sdk",
|
|
"@npm//open-in-idx",
|
|
"@npm//@webcontainer/api",
|
|
"@npm//@xterm/xterm",
|
|
"@npm//@xterm/addon-fit",
|
|
"@npm//algoliasearch",
|
|
"@npm//angular-split",
|
|
"@npm//zone.js",
|
|
]
|
|
|
|
TEST_DEPS = APPLICATION_DEPS + [
|
|
"@npm//@angular/platform-browser-dynamic",
|
|
"@npm//@types/jasmine",
|
|
"@npm//@types/node",
|
|
"@npm//jasmine",
|
|
"@npm//jasmine-core",
|
|
"@npm//karma-chrome-launcher",
|
|
"@npm//karma-coverage",
|
|
"@npm//karma-jasmine",
|
|
"@npm//karma-jasmine-html-reporter",
|
|
]
|
|
|
|
# Create `npm_link` targets for all dependencies that correspond to a
|
|
# first-party Angular package that can be built from `HEAD`.
|
|
link_local_packages(
|
|
all_deps = collections.uniq(APPLICATION_DEPS + TEST_DEPS),
|
|
)
|
|
|
|
copy_to_bin(
|
|
name = "application_files_bin",
|
|
srcs = APPLICATION_FILES,
|
|
)
|
|
|
|
bool_flag(
|
|
name = "prerender_adev",
|
|
build_setting_default = False,
|
|
)
|
|
|
|
config_setting(
|
|
name = "no_prerender",
|
|
flag_values = {
|
|
":prerender_adev": "false",
|
|
},
|
|
)
|
|
|
|
config_setting(
|
|
name = "prerender",
|
|
flag_values = {
|
|
":prerender_adev": "true",
|
|
},
|
|
)
|
|
|
|
config_based_architect_flags = select({
|
|
":no_prerender": ["--no-prerender"],
|
|
":prerender": ["--prerender"],
|
|
})
|
|
|
|
architect(
|
|
name = "build",
|
|
args = [
|
|
"angular-dev:build",
|
|
"--output-path=build",
|
|
] + config_based_architect_flags,
|
|
chdir = "$(RULEDIR)",
|
|
data = ensure_local_package_deps(APPLICATION_DEPS) + APPLICATION_ASSETS + [
|
|
":application_files_bin",
|
|
],
|
|
env = {
|
|
"NG_BUILD_OPTIMIZE_CHUNKS": "1",
|
|
},
|
|
# Network is required to inline fonts.
|
|
exec_properties = ENABLE_NETWORK,
|
|
output_dir = True,
|
|
tags = [
|
|
"no-remote-exec",
|
|
],
|
|
)
|
|
|
|
http_server(
|
|
name = "serve",
|
|
additional_root_paths = [
|
|
"angular/adev/build/browser",
|
|
],
|
|
enable_dev_ui = True,
|
|
deps = [":build"],
|
|
)
|
|
|
|
architect_test(
|
|
name = "test",
|
|
args = [
|
|
"angular-dev:test",
|
|
"--no-watch",
|
|
],
|
|
chdir = package_name(),
|
|
data = ensure_local_package_deps(TEST_DEPS) + TEST_FILES + APPLICATION_ASSETS + [
|
|
"//adev/tools:windows-chromium-path",
|
|
"@npm//@angular/build-tooling/bazel/browsers/chromium",
|
|
],
|
|
env = {
|
|
"CHROME_BIN": "../$(CHROMIUM)",
|
|
},
|
|
toolchains = [
|
|
"@npm//@angular/build-tooling/bazel/browsers/chromium:toolchain_alias",
|
|
],
|
|
)
|