Skip to content

Commit

Permalink
Create ng_js_binary macro to wrap esbuild for prod
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwillchen committed Dec 7, 2023
1 parent 73ba7cb commit 8274cd0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
2 changes: 2 additions & 0 deletions build_defs/defaults.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ load("@my_deps//:requirements.bzl", "requirement")
load("@rules_proto//proto:defs.bzl", _proto_library = "proto_library")
load("@rules_python//python:defs.bzl", _py_test = "py_test")
load("//build_defs:jspb_proto_library.bzl", _jspb_proto_library = "jspb_proto_library")
load("//build_defs:ng_js_binary.bzl", _ng_js_binary = "ng_js_binary")
load("//build_defs:py_proto_library.bzl", _py_proto_library = "py_proto_library")
load("//build_defs:sass_external_binary.bzl", _sass_external_binary = "sass_external_binary")
load("//tools:defaults.bzl", _devmode_esbuild = "devmode_esbuild", _esbuild = "esbuild", _esbuild_config = "esbuild_config", _http_server = "http_server", _ng_module = "ng_module", _sass_binary = "sass_binary", _ts_library = "ts_library")
Expand All @@ -18,6 +19,7 @@ esbuild = _esbuild
esbuild_config = _esbuild_config
http_server = _http_server
jspb_proto_library = _jspb_proto_library
ng_js_binary = _ng_js_binary
ng_module = _ng_module
pkg_web = _pkg_web
proto_library = _proto_library
Expand Down
18 changes: 18 additions & 0 deletions build_defs/ng_js_binary.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""Wrapper for building a js binary.
"""

load("//tools/angular:index.bzl", "LINKER_PROCESSED_FW_PACKAGES")
load("//tools:defaults.bzl", "esbuild")

def ng_js_binary(name, deps = [], entry_points = []):
esbuild(
name = name,
config = "//web/src/app:esbuild_config",
entry_points = entry_points,
platform = "browser",
splitting = True,
# We cannot use `ES2017` or higher as that would result in `async/await` not being downleveled.
# ZoneJS needs to be able to intercept these as otherwise change detection would not work properly.
target = "es2016",
deps = LINKER_PROCESSED_FW_PACKAGES + deps,
)
12 changes: 3 additions & 9 deletions web/src/app/prod/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("//build_defs:defaults.bzl", "ANGULAR_CORE_DEPS", "LINKER_PROCESSED_FW_PACKAGES", "esbuild", "ng_module", "pkg_web")
load("//build_defs:defaults.bzl", "ANGULAR_CORE_DEPS", "ng_js_binary", "ng_module", "pkg_web")

package(
default_visibility = ["//build_defs:optic_internal"],
Expand All @@ -14,16 +14,10 @@ ng_module(
] + ANGULAR_CORE_DEPS,
)

esbuild(
ng_js_binary(
name = "bundles",
config = "//web/src/app:esbuild_config",
entry_points = [":main.ts"],
platform = "browser",
splitting = True,
# We cannot use `ES2017` or higher as that would result in `async/await` not being downleveled.
# ZoneJS needs to be able to intercept these as otherwise change detection would not work properly.
target = "es2016",
deps = LINKER_PROCESSED_FW_PACKAGES + [
deps = [
":main",
],
)
Expand Down

0 comments on commit 8274cd0

Please sign in to comment.