This repository was archived by the owner on Apr 4, 2025. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathBUILD.bazel
More file actions
203 lines (186 loc) Β· 6.62 KB
/
Copy pathBUILD.bazel
File metadata and controls
203 lines (186 loc) Β· 6.62 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
load("@build_bazel_rules_nodejs//:defs.bzl", "history_server", "rollup_bundle")
load("@build_bazel_rules_nodejs//internal/web_package:web_package.bzl", "web_package")
load("@io_bazel_rules_docker//container:container.bzl", "container_image")
load("@io_bazel_rules_docker//nodejs:image.bzl", "nodejs_image")
load("@io_bazel_rules_sass//:defs.bzl", "sass_binary")
load("@npm_angular_bazel//:index.bzl", "ng_module")
load("@npm_bazel_typescript//:defs.bzl", "ts_config", "ts_devserver", "ts_library")
package(default_visibility = ["//:__subpackages__"])
ts_config(
name = "tsconfig-test",
src = "tsconfig-test.json",
deps = [":tsconfig.json"],
)
# Run the sass compiler to output "styles.css"
# TODO(alexeagle): demonstrate the sass_library rule too
sass_binary(
name = "styles",
src = "styles.scss",
)
# We don't import from these, but the generated ngfactory code will
NG_FACTORY_ADDED_IMPORTS = [
"@npm//@angular/animations",
"@npm//@angular/cdk",
"@npm//@angular/material",
"@npm//@angular/forms",
]
ts_library(
name = "initialize_testbed",
testonly = 1,
srcs = [
"initialize_testbed.ts",
],
deps = [
"@npm//@angular/core",
"@npm//@angular/platform-browser-dynamic",
"@npm//@types",
],
)
ng_module(
name = "src",
srcs = [
"main.dev.ts",
"main.prod.ts",
],
tsconfig = ":tsconfig.json",
deps = NG_FACTORY_ADDED_IMPORTS + [
"//src/app",
"@npm//@angular/core",
"@npm//@angular/platform-browser",
"@npm//@angular/router",
"@npm//@ngrx/store",
],
)
filegroup(
name = "rxjs_umd_modules",
srcs = [
":rxjs_shims.js",
"@npm//:node_modules/rxjs/bundles/rxjs.umd.js",
],
)
# We always strip these paths off the front of any assets we serve
_ROOT_DIRS = [
"npm/node_modules/zone.js/dist",
"npm/node_modules/@angular/material/prebuilt-themes",
"npm/node_modules/@ngrx/store/bundles",
]
# Files that we serve in both development and production
_ASSETS = [
# This label references an output of the "styles" sass_binary above.
":styles.css",
# Directly reference a file that came from @angular/material npm package
"@npm//:node_modules/@angular/material/prebuilt-themes/deeppurple-amber.css",
# We load zone.js outside the bundle. That's because it's a "pollyfill"
# which speculates that such features might be available in a browser.
# Also it's tricky to configure dead code elimination to understand that
# zone.js is used, given that we don't have any import statement that
# imports from it.
"@npm//:node_modules/zone.js/dist/zone.min.js",
]
# This devserver is written in Go and is super-fast.
# It doesn't run any bundler or code splitter. Instead, it concatenates
# named UMD and named AMD JavaScript code on-the-fly in-memory.
# This scales really well for massive codebases.
ts_devserver(
name = "devserver",
# serve these files rooted at /
additional_root_paths = _ROOT_DIRS,
# Serve these files but don't inject tags for them into the index file
# This might be because we only want to lazy-load these scripts on-demand,
# or because they aren't compatible with Require.js so we must use a runtime
# loader to load them.
data = [
"//src/assets",
"@npm//:node_modules/@ngrx/store/bundles/store.umd.min.js",
],
# Start from the development version of the main
entry_module = "angular_bazel_example/src/main.dev",
# <script> and <link> tags will be automatically injected into this index file
index_html = "//src/example:assets",
# These scripts will be included in the JS bundle after require.js
# They should have only named UMD modules, or require.js will throw.
scripts = [
"@npm//:node_modules/tslib/tslib.js",
":rxjs_umd_modules",
":require.config.js",
# We are manaully adding the bazel generated named-UMD date-fns bundle here as
# named-UMD bundles for non-APF npm packages are not yet automatically added.
# This file is generated by the npm_umd_bundle @npm//date-fns:date-fns__umd
# rule that is setup by yarn_install.
"@npm//date-fns:date-fns.umd.js",
],
# Serve these files in addition to the JavaScript bundle
# The corresponding <script> or <link> tags will be injected into the index_html
static_files = _ASSETS,
# Tell Bazel to build the sources first
deps = ["//src"],
)
rollup_bundle(
name = "bundle",
entry_point = ":main.prod.ts",
deps = [
"//src",
"@npm//@angular/common",
"@npm//@angular/core",
"@npm//@angular/material",
"@npm//@angular/platform-browser",
"@npm//@angular/router",
"@npm//@ngrx/store",
"@npm//rxjs",
],
)
web_package(
name = "prodapp",
additional_root_paths = _ROOT_DIRS + [
# In production mode we also serve some polyfills
"npm/node_modules/core-js/client",
"npm/node_modules/systemjs/dist",
],
# do not sort
assets = _ASSETS + [
# For differential loading, we supply both an ESModule entry point and an es5 entry point
# The injector will put two complimentary script tags in the example.html
":bundle.min.js",
":bundle.min.es2015.js",
],
data = [
":bundle",
"//src/assets",
# Include polyfills that will be requested by old browsers
"@npm//:node_modules/systemjs/dist/system.js",
"@npm//:node_modules/core-js/client/core.min.js",
"index.html",
],
# <script> and <link> tags will be automatically injected into this index.
index_html = "//src/example:assets",
)
history_server(
name = "prodserver",
data = [":prodapp"],
# '-a src/prodapp' will ask history-server to scan for all apps under the
# given folder this will result in the following auto-configuration:
# /example => src/prodapp/example
# / => src/prodapp
templated_args = [
"-a",
"src/prodapp",
],
)
nodejs_image(
name = "nodejs_image",
data = [":prodapp"],
entry_point = "@history-server_runtime_deps//:node_modules/history-server/modules/cli.js",
node_modules = "@history-server_runtime_deps//:node_modules",
# Actions created by this rule are I/O-bound,
# so there is no benefit to running them remotely
tags = ["local"],
templated_args = ["src/prodapp"],
)
container_image(
name = "image",
base = ":nodejs_image",
# Actions created by this rule are I/O-bound,
# so there is no benefit to running them remotely
tags = ["local"],
workdir = "/app/src/nodejs_image.binary.runfiles/angular_bazel_example",
)