Updates to rules_nodejs 2.2.0. This is the first major release in 7 months and includes a number of features as well as breaking changes. Release notes: https://github.com/bazelbuild/rules_nodejs/releases/tag/2.0.0 Features of note for angular/angular: * stdout/stderr/exit code capture; this could be potentially be useful * TypeScript (ts_project); a simpler tsc rule that ts_library that can be used in the repo where ts_library is too heavy weight Breaking changes of note for angular/angular: * loading custom rules from npm packages: `ts_library` is no longer loaded from `@npm_bazel_typescript//:index.bzl` (which no longer exists) but is now loaded from `@npm//@bazel/typescript:index.bzl` * with the loading changes above, `load("@npm//:install_bazel_dependencies.bzl", "install_bazel_dependencies")` is no longer needed in the WORKSPACE which also means that yarn_install does not need to run unless building/testing a target that depends on @npm. In angular/angular this is a minor improvement as almost everything depends on @npm. * @angular/bazel package is also updated in this PR to support the new load location; Angular + Bazel users that require it for ng_package (ng_module is no longer needed in OSS with Angular 10) will need to load from `@npm//@angular/bazel:index.bzl`. I investigated if it was possible to maintain backward compatability for the old load location `@npm_angular_bazel` but it is not since the package itself needs to be updated to load from `@npm//@bazel/typescript:index.bzl` instead of `@npm_bazel_typescript//:index.bzl` as it depends on ts_library internals for ng_module. * runfiles.resolve will now throw instead of returning undefined to match behavior of node require Other changes in angular/angular: * integration/bazel has been updated to use both ng_module and ts_libary with use_angular_plugin=true. The latter is the recommended way for rules_nodejs users to compile Angular 10 with Ivy. Bazel + Angular ViewEngine is supported with @angular/bazel <= 9.0.5 and Angular <= 8. There is still Angular ViewEngine example on rules_nodejs https://github.com/bazelbuild/rules_nodejs/tree/stable/examples/angular_view_engine on these older versions but users that want to update to Angular 10 and are on Bazel must switch to Ivy and at that point ts_library with use_angular_plugin=true is more performant that ng_module. Angular example in rules_nodejs is configured this way as well: https://github.com/bazelbuild/rules_nodejs/tree/stable/examples/angular. As an aside, we also have an example of building Angular 10 with architect() rule directly instead of using ts_library with angular plugin: https://github.com/bazelbuild/rules_nodejs/tree/stable/examples/angular_bazel_architect. NB: ng_module is still required for angular/angular repository as it still builds ViewEngine & @angular/bazel also provides the ng_package rule. ng_module can be removed in the future if ViewEngine is no longer needed in angular repo. * JSModuleInfo provider added to ng_module. this is for forward compat for future rules_nodejs versions. PR Close #39182
101 lines
3.9 KiB
Python
101 lines
3.9 KiB
Python
# Copyright Google LLC All Rights Reserved.
|
|
#
|
|
# Use of this source code is governed by an MIT-style license that can be
|
|
# found in the LICENSE file at https://angular.io/license
|
|
|
|
load("@build_bazel_rules_nodejs//:index.bzl", "npm_package_bin")
|
|
load("@npm//@bazel/terser:index.bzl", "terser_minified")
|
|
load("@npm//@bazel/rollup:index.bzl", "rollup_bundle")
|
|
load("//dev-infra/bazel:expand_template.bzl", "expand_template")
|
|
|
|
def ng_rollup_bundle(
|
|
name,
|
|
entry_point,
|
|
deps = [],
|
|
license_banner = None,
|
|
build_optimizer = True,
|
|
visibility = None,
|
|
format = "iife",
|
|
globals = {},
|
|
**kwargs):
|
|
"""Rollup with Build Optimizer on target prodmode output (ESM2015).
|
|
|
|
This provides an extension of the [rollup_bundle] rule that works better for Angular apps.
|
|
|
|
Runs [rollup], [terser_minified] and [brotli] to produce a number of output bundles.
|
|
|
|
es2015 : "%{name}.js"
|
|
es2015 minified : "%{name}.min.js"
|
|
es2015 minified (compressed) : "%{name}.min.js.br",
|
|
es2015 minified (debug) : "%{name}.min_debug.js"
|
|
|
|
It registers `@angular-devkit/build-optimizer` as a rollup plugin by default. This helps
|
|
with further optimization. See https://github.com/angular/angular-cli/tree/master/packages/angular_devkit/build_optimizer.
|
|
|
|
[rollup_bundle]: https://github.com/bazelbuild/rules_nodejs/blob/1.x/packages/rollup/src/rollup_bundle.bzl
|
|
[rollup]: https://rollupjs.org/guide/en/
|
|
[terser_minified]: https://bazelbuild.github.io/rules_nodejs/Terser.html
|
|
[brotli]: https://brotli.org/
|
|
"""
|
|
|
|
config_data = [license_banner] if license_banner else []
|
|
|
|
expand_template(
|
|
name = "%s_rollup_config" % name,
|
|
template = "//dev-infra/benchmark/ng_rollup_bundle:rollup.config-tmpl.js",
|
|
output_name = "%s_rollup_config.js" % name,
|
|
configuration_env_vars = ["angular_ivy_enabled"],
|
|
data = config_data,
|
|
substitutions = {
|
|
"TMPL_build_optimizer": "true" if build_optimizer else "false",
|
|
"TMPL_banner_file": "\"$(execpath %s)\"" % license_banner if license_banner else "undefined",
|
|
"TMPL_external": ", ".join(["'%s'" % e for e in globals.keys()]),
|
|
"TMPL_globals": ", ".join(["'%s': '%s'" % (g, g) for g in globals]),
|
|
},
|
|
visibility = visibility,
|
|
)
|
|
|
|
rollup_bundle(
|
|
name = name,
|
|
config_file = "%s_rollup_config" % name,
|
|
entry_points = {
|
|
(entry_point): name,
|
|
},
|
|
visibility = visibility,
|
|
deps = config_data + deps + [
|
|
"@npm//rollup-plugin-node-resolve",
|
|
"@npm//rollup-plugin-sourcemaps",
|
|
"@npm//rollup-plugin-commonjs",
|
|
"@npm//@angular-devkit/build-optimizer",
|
|
],
|
|
silent = True,
|
|
format = format,
|
|
sourcemap = "true",
|
|
**kwargs
|
|
)
|
|
|
|
common_terser_options = {
|
|
"visibility": visibility,
|
|
"config_file": "//dev-infra/benchmark/ng_rollup_bundle:terser_config.json",
|
|
# TODO: Enable source maps for better debugging when `@bazel/terser` pre-declares
|
|
# JS and map outputs. Tracked with: DEV-120
|
|
"sourcemap": False,
|
|
}
|
|
|
|
terser_minified(name = name + ".min", src = name + ".js", **common_terser_options)
|
|
native.filegroup(name = name + ".min.js", srcs = [name + ".min"], visibility = visibility)
|
|
terser_minified(name = name + ".min_debug", src = name + ".js", debug = True, **common_terser_options)
|
|
native.filegroup(name = name + ".min_debug.js", srcs = [name + ".min_debug"], visibility = visibility)
|
|
|
|
npm_package_bin(
|
|
name = "_%s_brotli" % name,
|
|
tool = "//dev-infra/benchmark/brotli-cli",
|
|
data = [name + ".min.js"],
|
|
outs = [name + ".min.js.br"],
|
|
args = [
|
|
"--output=$(execpath %s.min.js.br)" % name,
|
|
"$(execpath %s.min.js)" % name,
|
|
],
|
|
visibility = visibility,
|
|
)
|