Skip to content

Commit e48b960

Browse files
devversionmmalerba
authored andcommitted
build: add target to create dev-app web package (#17937)
Creates a new Bazel target that can be built to create a static web package of the dev-app. The web package can be deployed to Firebase or other static file hosting services. In a follow-up, we can create a script that replicates what the old firebase deploy gulp task did.
1 parent 0ec499d commit e48b960

File tree

2 files changed

+49
-6
lines changed

2 files changed

+49
-6
lines changed

src/dev-app/BUILD.bazel

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package(default_visibility = ["//visibility:public"])
22

3+
load("@build_bazel_rules_nodejs//:index.bzl", "pkg_web")
4+
load("@build_bazel_rules_nodejs//internal/common:devmode_js_sources.bzl", "devmode_js_sources")
35
load("//src/cdk:config.bzl", "CDK_ENTRYPOINTS")
46
load("//src/cdk-experimental:config.bzl", "CDK_EXPERIMENTAL_ENTRYPOINTS")
57
load("//src/material:config.bzl", "MATERIAL_ENTRYPOINTS")
@@ -111,8 +113,11 @@ expand_template(
111113
template = "system-config-tmpl.js",
112114
)
113115

114-
dev_server(
115-
name = "devserver",
116+
# File group for all static files which are needed to serve the dev-app. These files are
117+
# used in the devserver as runfiles and will be copied into the static web package that can
118+
# be deployed on static hosting services (like firebase).
119+
filegroup(
120+
name = "dev_app_static_files",
116121
srcs = [
117122
"favicon.ico",
118123
"index.html",
@@ -158,10 +163,40 @@ dev_server(
158163
"@npm//:node_modules/tslib/tslib.js",
159164
"@npm//:node_modules/zone.js/dist/zone.js",
160165
],
166+
)
167+
168+
dev_server(
169+
name = "devserver",
170+
srcs = [":dev_app_static_files"],
161171
additional_root_paths = [
162172
"npm/node_modules",
173+
# Needed for compatibility with "pkg_web" which always uses the tree
174+
# artifact output as workspace root.
175+
"angular_material",
163176
],
164177
deps = [
165178
":dev-app",
166179
],
167180
)
181+
182+
# Collects all ES5 JavaScript files which are required to serve the dev-app. By default,
183+
# ts_library and ng_module targets only expose the type definition files as outputs.
184+
devmode_js_sources(
185+
name = "dev_app_js_sources",
186+
tags = ["manual"],
187+
deps = [":dev-app"],
188+
)
189+
190+
# Target that builds a static web package of the dev-app. The web package can be
191+
# deployed on static hosting services (such as firebase).
192+
pkg_web(
193+
name = "web_package",
194+
srcs = [
195+
":dev_app_js_sources",
196+
":dev_app_static_files",
197+
],
198+
additional_root_paths = [
199+
"npm/node_modules",
200+
],
201+
tags = ["manual"],
202+
)

src/dev-app/system-config-tmpl.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,15 @@ var MATERIAL_EXPERIMENTAL_PACKAGES = $MATERIAL_EXPERIMENTAL_ENTRYPOINTS_TMPL;
1818
/** Whether the dev-app is served with Ivy enabled. */
1919
var isRunningWithIvy = '$ANGULAR_IVY_ENABLED_TMPL'.toString() === 'True';
2020

21-
/** Bazel runfile path referring to the "src/" folder of the project. */
22-
var srcRunfilePath = 'angular_material/src';
21+
/** Bazel runfile path referring to the "src" folder of the project. */
22+
var srcRunfilePath = 'src';
2323

2424
/** Path mappings that will be registered in SystemJS. */
2525
var pathMapping = {};
2626

2727
/** Package configurations that will be used in SystemJS. */
2828
var packagesConfig = {};
2929

30-
31-
3230
// Configure all primary entry-points.
3331
configureEntryPoint('cdk');
3432
configureEntryPoint('cdk-experimental');
@@ -60,6 +58,9 @@ function configureEntryPoint(pkgName, entryPoint) {
6058

6159
pathMapping['@angular/' + name] = srcRunfilePath + '/' + name;
6260
pathMapping['@angular/' + examplesName] = srcRunfilePath + '/' + examplesName;
61+
62+
// Ensure that imports which resolve to the entry-point directory are
63+
// redirected to the "index.js" file of the directory.
6364
packagesConfig[srcRunfilePath + '/' + name] =
6465
packagesConfig[srcRunfilePath + '/' + examplesName] = {main: 'index.js'};
6566
}
@@ -77,6 +78,13 @@ function getBundlePath(bundleName, basePath) {
7778
}
7879

7980
var map = Object.assign({
81+
// Maps imports where the AMD module names start with workspace name (commonly done in Bazel).
82+
// This is needed for compatibility with dynamic runfile resolution of the devserver and the
83+
// static runfile resolution done in the "pkg_web" rule. In the built web package, the output
84+
// tree artifact serves as workspace root and root of the current dev-app Bazel package.
85+
'angular_material': '',
86+
'angular_material/src/dev-app': '',
87+
8088
'main': 'main.js',
8189
'tslib': 'tslib/tslib.js',
8290
'moment': 'moment/min/moment-with-locales.min.js',

0 commit comments

Comments
 (0)