Skip to content

Commit 1601ee6

Browse files
devversionmhevery
authored andcommitted
refactor(dev-infra): ng_rollup_bundle rule should leverage @bazel/rollup (angular#37623)
Refactors the `ng_rollup_bundle` rule to a macro that relies on the `@bazel/rollup` package. This means that the rule no longer deals with custom ESM5 flavour output, but rather only builds prodmode ES2015 output. This matches the common build output in Angular projects, and optimizations done in CLI where ES2015 is the default optimization input. The motiviation for this change is: * Not duplicating rollup Bazel rules. Instead leveraging the official rollup rule. * Not dealing with a third TS output flavor in Bazel.The ESM5 flavour has the potential of slowing down local development (as it requires compilation replaying) * Updating the rule to be aligned with current CLI optimizations. This also _fixes_ a bug that surfaced in the old rollup bundle rule. Code that is unused, is not removed properly. The new rule fixes this by setting the `toplevel` flag. This instructs terser to remove unused definitions at top-level. This matches the optimization applied in CLI projects. Notably the CLI doesn't need this flag, as code is always wrapped by Webpack. Hence, the unused code eliding runs by default. PR Close angular#37623
1 parent 6898eab commit 1601ee6

30 files changed

Lines changed: 293 additions & 757 deletions

File tree

dev-infra/bazel/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package(default_visibility = ["//visibility:public"])
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""Implementation of the expand_template rule """
2+
3+
def expand_template_impl(ctx):
4+
substitutions = dict()
5+
6+
for k in ctx.attr.configuration_env_vars:
7+
if k in ctx.var.keys():
8+
substitutions["TMPL_%s" % k] = ctx.var[k]
9+
10+
for k in ctx.attr.substitutions:
11+
substitutions[k] = ctx.expand_location(ctx.attr.substitutions[k], targets = ctx.attr.data)
12+
13+
ctx.actions.expand_template(
14+
template = ctx.file.template,
15+
output = ctx.outputs.output_name,
16+
substitutions = substitutions,
17+
)
18+
19+
"""Rule that can be used to substitute variables in a given template file."""
20+
expand_template = rule(
21+
implementation = expand_template_impl,
22+
attrs = {
23+
"configuration_env_vars": attr.string_list(
24+
default = [],
25+
doc = "Bazel configuration variables which should be exposed to the template.",
26+
),
27+
"output_name": attr.output(
28+
mandatory = True,
29+
doc = "File where the substituted template is written to.",
30+
),
31+
"substitutions": attr.string_dict(
32+
mandatory = True,
33+
doc = "Dictionary of substitutions that should be available to the template. Dictionary key represents the placeholder in the template.",
34+
),
35+
"data": attr.label_list(
36+
doc = """Data dependencies for location expansion.""",
37+
allow_files = True,
38+
),
39+
"template": attr.label(
40+
mandatory = True,
41+
allow_single_file = True,
42+
doc = "File used as template.",
43+
),
44+
},
45+
)

dev-infra/benchmark/component_benchmark/component_benchmark.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def component_benchmark(
132132
bootstrap = ["//packages/zone.js/bundles:zone.umd.js"],
133133
port = 4200,
134134
static_files = assets + styles,
135-
deps = [":" + app_main + ".min_debug.es2015.js"],
135+
deps = [":" + app_main + ".min_debug.js"],
136136
additional_root_paths = ["//dev-infra/benchmark/component_benchmark/defaults"],
137137
serving_path = "/app_bundle.js",
138138
)

dev-infra/benchmark/ng_rollup_bundle/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package(default_visibility = ["//visibility:public"])
33
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary")
44

55
exports_files([
6-
"rollup.config.js",
6+
"rollup.config-tmpl.js",
77
"terser_config.json",
88
])
99

0 commit comments

Comments
 (0)