blob: 966eb643abc2fdf35a9658c837fefa5522851af2 [file] [log] [blame]
Sean Condon98b6ddb2019-12-24 08:07:40 +00001"""
2 Copyright 2020-present Open Networking Foundation
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15"""
16
17package(default_visibility = ["//:__subpackages__"])
18
19load("@build_bazel_rules_nodejs//:index.bzl", "pkg_web")
20load("@io_bazel_rules_sass//:defs.bzl", "sass_binary")
21load("@npm//history-server:index.bzl", "history_server")
Sean Condona3ad7792020-01-04 19:26:34 +000022load("@npm//html-insert-assets:index.bzl", "html_insert_assets")
Sean Condon98b6ddb2019-12-24 08:07:40 +000023load("@npm_angular_bazel//:index.bzl", "ng_module")
24load("@npm_bazel_rollup//:index.bzl", "rollup_bundle")
25load("@npm_bazel_terser//:index.bzl", "terser_minified")
26load("@npm_bazel_typescript//:index.bzl", "ts_config", "ts_devserver", "ts_library")
27
28#load("@npm_bazel_karma//:index.bzl", "ts_web_test_suite")
29
Sean Condona3ad7792020-01-04 19:26:34 +000030exports_files([
31 "WEB-INF/web.xml",
32])
Sean Condon98b6ddb2019-12-24 08:07:40 +000033
34# We don't import from these, but the generated ngfactory code will
35NG_FACTORY_ADDED_IMPORTS = [
36 "@npm//@angular/animations",
37 "@npm//@angular/forms",
38]
39
40ng_module(
41 name = "gui2",
42 srcs = [
43 "environments/environment.prod.ts",
Sean Condona3ad7792020-01-04 19:26:34 +000044 "onos.dev.ts",
Sean Condon98b6ddb2019-12-24 08:07:40 +000045 "onos.prod.ts",
46 ],
Sean Condona3ad7792020-01-04 19:26:34 +000047 tsconfig = "//web/gui2:tsconfig.json",
Sean Condon98b6ddb2019-12-24 08:07:40 +000048 deps = NG_FACTORY_ADDED_IMPORTS + [
49 "//web/gui2/src/main/webapp/app:app",
50 "@npm//@angular/core",
51 "@npm//@angular/platform-browser",
52 "@npm//@angular/router",
53 ],
54)
55
56rollup_bundle(
57 name = "bundle-es2015",
58 config_file = "rollup.config.js",
59 entry_points = {
60 ":onos.prod.ts": "index",
61 },
62 output_dir = True,
63 deps = [
64 "//web/gui2/src/main/webapp:gui2",
65 "@npm//rollup-plugin-commonjs",
66 "@npm//rollup-plugin-node-resolve",
67 ],
68)
69
70terser_minified(
71 name = "bundle-es2015.min",
72 src = ":bundle-es2015",
73)
74
75# Files that we serve in both development and production
76_ASSETS = [
77 # This label references an output of the "styles" sass_binary above.
78 ":onos.global.css",
79 "//web/gui:src/main/webapp/data",
80 "fonts/open-sans-v15-latin-300.woff",
81 "fonts/open-sans-v15-latin-300.woff2",
82 "fonts/open-sans-v15-latin-600.woff",
83 "fonts/open-sans-v15-latin-600.woff2",
84 "fonts/open-sans-v15-latin-700.woff",
85 "fonts/open-sans-v15-latin-700.woff2",
86 "error.html",
87 "login.html",
88 "nav.html",
89 "not-ready.html",
90 # We load zone.js outside the bundle. That's because it's a "pollyfill"
91 # which speculates that such features might be available in a browser.
92 # Also it's tricky to configure dead code elimination to understand that
93 # zone.js is used, given that we don't have any import statement that
94 # imports from it.
95 "@npm//:node_modules/zone.js/dist/zone.min.js",
96]
97
98pkg_web(
99 name = "prodapp",
100 srcs = _ASSETS + [
101 ":bundle-es2015.min",
102 # Include polyfills that will be requested by old browsers
103 # "@npm//:node_modules/systemjs/dist/system.js",
104 # "@npm//:node_modules/core-js/client/core.min.js",
Sean Condona3ad7792020-01-04 19:26:34 +0000105 ":index.html",
Sean Condon98b6ddb2019-12-24 08:07:40 +0000106 ],
107 # In production mode we serve some polyfills with script tags that have hard-coded paths in the index.html
108 # so we must serve them at that path, by stripping a prefix
109 additional_root_paths = [
110 "web/gui/src/main/webapp",
111 ],
112)
113
114history_server(
115 name = "prodserver",
116 data = [":prodapp"],
117 # '-a src/prodapp' will ask history-server to scan for all apps under the
118 # given folder this will result in the following auto-configuration:
119 # /example => src/prodapp/example
120 # / => src/prodapp
121 templated_args = [
122 "-a",
123 "web/gui2/src/main/webapp/prodapp",
124 ],
125)
126
Sean Condona3ad7792020-01-04 19:26:34 +0000127filegroup(
128 name = "rxjs_umd_modules",
129 srcs = [
130 ":rxjs_shims.js",
131 "@npm//:node_modules/rxjs/bundles/rxjs.umd.js",
132 ],
133)
134
135# Convert d3 to an AMD module so it can be loaded in the RequireJS test environment.
Sean Condon98b6ddb2019-12-24 08:07:40 +0000136genrule(
Sean Condona3ad7792020-01-04 19:26:34 +0000137 name = "d3_requirejs",
138 srcs = [
139 "@npm//:node_modules/d3/dist/d3.js",
140 ],
141 outs = [
142 "d3.js",
143 ],
144 cmd = """echo "define('d3', function(require, exports, module) {" > $@ \
145 && cat $< >> $@ \
146 && echo '});' >> $@""",
147)
148
149ts_library(
150 name = "initialize_testbed",
151 testonly = 1,
152 srcs = [
153 "initialize_testbed.ts",
154 ],
155 tsconfig = "//web/gui2:tsconfig.json",
156 deps = [
157 "@npm//@angular/core",
158 "@npm//@angular/platform-browser-dynamic",
159 "@npm//@types",
160 ],
Sean Condon98b6ddb2019-12-24 08:07:40 +0000161)