-
Notifications
You must be signed in to change notification settings - Fork 0
/
defs.bzl
81 lines (73 loc) · 3.12 KB
/
defs.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
load("@aspect_bazel_lib//lib:copy_to_directory.bzl", "copy_to_directory")
load("@aspect_rules_esbuild//esbuild:defs.bzl", "esbuild")
load("@npm//:history-server/package_json.bzl", history_server_bin = "bin")
load("@npm//:html-insert-assets/package_json.bzl", html_insert_assets_bin = "bin")
load("//tools:ng.bzl", "ng_esbuild", "ng_project")
load("//tools:ts.bzl", "ts_project")
NG_DEV_DEFINE = {
"process.env.NODE_ENV": "'development'",
"ngJitMode": "false",
}
NG_PROD_DEFINE = {
"process.env.NODE_ENV": "'production'",
"ngDevMode": "false",
"ngJitMode": "false",
}
def pkg_web(name, index_html, entry_point, entry_deps, html_assets, script_assets, assets, production, visibility = None):
""" Bundle and create runnable web package.
For a given application entry_point, assets and defined constants... generate
a bundle using that entry and constants, an index.html referencing the bundle and
providated assets, package all content into a resulting directory of the given name.
"""
bundle = "bundle-%s" % name
esbuild(
name = bundle,
entry_points = [entry_point],
srcs = entry_deps,
define = NG_PROD_DEFINE if production else NG_DEV_DEFINE,
format = "esm",
config = "//tools:ngc.esbuild",
deps = [
# for config
"//:node_modules/@angular/compiler-cli",
"//:node_modules/@babel/core",
"//:node_modules/@types/babel__core",
"//:node_modules/@types/node",
],
output_dir = True,
splitting = True,
metafile = False,
minify = production,
visibility = ["//visibility:private"],
)
html_out = "_%s_html" % name
html_insert_assets_bin.html_insert_assets(
name = html_out,
outs = ["%s/index.html" % html_out],
args = [
# Template HTML file.
"--html",
"$(location %s)" % index_html,
# Output HTML file.
"--out",
"%s/%s/index.html" % (native.package_name(), html_out),
# Root directory prefixes to strip from asset paths.
"--roots",
native.package_name(),
"%s/%s" % (native.package_name(), html_out),
] +
# Generic Assets
["--assets"] + ["$(rootpath %s)" % s for s in html_assets] +
["--scripts", "--module"] + ["$(rootpath %s)" % s for s in script_assets] +
["--scripts", "--module", "%s/%s" % (bundle, entry_point)] +
(["--scripts", "--async", "http://localhost:35729/livereload.js"] if not production else []),
# The input HTML template, all assets for potential access for stamping
srcs = [index_html, ":%s" % bundle] + html_assets + script_assets,
visibility = ["//visibility:private"],
)
copy_to_directory(
name = name,
srcs = [":%s" % bundle, ":%s" % html_out] + html_assets + assets + script_assets,
root_paths = [".", "%s/%s" % (native.package_name(), html_out)],
visibility = visibility,
)