blob: 3b834e97624dea9d825390434db8e7210f6108b2 [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",
Sean Condonf86cfc92020-04-14 15:10:03 +010032 "karma.conf.js",
Sean Condona3ad7792020-01-04 19:26:34 +000033])
Sean Condon98b6ddb2019-12-24 08:07:40 +000034
35# We don't import from these, but the generated ngfactory code will
36NG_FACTORY_ADDED_IMPORTS = [
37 "@npm//@angular/animations",
38 "@npm//@angular/forms",
39]
40
41ng_module(
42 name = "gui2",
43 srcs = [
44 "environments/environment.prod.ts",
Sean Condona3ad7792020-01-04 19:26:34 +000045 "onos.dev.ts",
Sean Condon98b6ddb2019-12-24 08:07:40 +000046 "onos.prod.ts",
47 ],
Sean Condona3ad7792020-01-04 19:26:34 +000048 tsconfig = "//web/gui2:tsconfig.json",
Sean Condon98b6ddb2019-12-24 08:07:40 +000049 deps = NG_FACTORY_ADDED_IMPORTS + [
50 "//web/gui2/src/main/webapp/app:app",
51 "@npm//@angular/core",
52 "@npm//@angular/platform-browser",
53 "@npm//@angular/router",
54 ],
55)
56
57rollup_bundle(
58 name = "bundle-es2015",
59 config_file = "rollup.config.js",
60 entry_points = {
61 ":onos.prod.ts": "index",
62 },
63 output_dir = True,
64 deps = [
65 "//web/gui2/src/main/webapp:gui2",
66 "@npm//rollup-plugin-commonjs",
67 "@npm//rollup-plugin-node-resolve",
68 ],
69)
70
71terser_minified(
72 name = "bundle-es2015.min",
73 src = ":bundle-es2015",
74)
75
76# Files that we serve in both development and production
77_ASSETS = [
78 # This label references an output of the "styles" sass_binary above.
79 ":onos.global.css",
80 "//web/gui:src/main/webapp/data",
81 "fonts/open-sans-v15-latin-300.woff",
82 "fonts/open-sans-v15-latin-300.woff2",
83 "fonts/open-sans-v15-latin-600.woff",
84 "fonts/open-sans-v15-latin-600.woff2",
85 "fonts/open-sans-v15-latin-700.woff",
86 "fonts/open-sans-v15-latin-700.woff2",
87 "error.html",
88 "login.html",
89 "nav.html",
90 "not-ready.html",
91 # We load zone.js outside the bundle. That's because it's a "pollyfill"
92 # which speculates that such features might be available in a browser.
93 # Also it's tricky to configure dead code elimination to understand that
94 # zone.js is used, given that we don't have any import statement that
95 # imports from it.
96 "@npm//:node_modules/zone.js/dist/zone.min.js",
97]
98
99pkg_web(
100 name = "prodapp",
101 srcs = _ASSETS + [
102 ":bundle-es2015.min",
103 # Include polyfills that will be requested by old browsers
104 # "@npm//:node_modules/systemjs/dist/system.js",
105 # "@npm//:node_modules/core-js/client/core.min.js",
Sean Condona3ad7792020-01-04 19:26:34 +0000106 ":index.html",
Sean Condon98b6ddb2019-12-24 08:07:40 +0000107 ],
108 # In production mode we serve some polyfills with script tags that have hard-coded paths in the index.html
109 # so we must serve them at that path, by stripping a prefix
110 additional_root_paths = [
111 "web/gui/src/main/webapp",
112 ],
113)
114
115history_server(
116 name = "prodserver",
117 data = [":prodapp"],
118 # '-a src/prodapp' will ask history-server to scan for all apps under the
119 # given folder this will result in the following auto-configuration:
120 # /example => src/prodapp/example
121 # / => src/prodapp
122 templated_args = [
123 "-a",
124 "web/gui2/src/main/webapp/prodapp",
125 ],
126)
127
Sean Condona3ad7792020-01-04 19:26:34 +0000128filegroup(
129 name = "rxjs_umd_modules",
130 srcs = [
131 ":rxjs_shims.js",
132 "@npm//:node_modules/rxjs/bundles/rxjs.umd.js",
133 ],
134)
135
136# Convert d3 to an AMD module so it can be loaded in the RequireJS test environment.
Sean Condon98b6ddb2019-12-24 08:07:40 +0000137genrule(
Sean Condona3ad7792020-01-04 19:26:34 +0000138 name = "d3_requirejs",
139 srcs = [
140 "@npm//:node_modules/d3/dist/d3.js",
141 ],
142 outs = [
143 "d3.js",
144 ],
145 cmd = """echo "define('d3', function(require, exports, module) {" > $@ \
146 && cat $< >> $@ \
147 && echo '});' >> $@""",
148)
149
150ts_library(
151 name = "initialize_testbed",
152 testonly = 1,
153 srcs = [
154 "initialize_testbed.ts",
155 ],
156 tsconfig = "//web/gui2:tsconfig.json",
157 deps = [
158 "@npm//@angular/core",
159 "@npm//@angular/platform-browser-dynamic",
160 "@npm//@types",
161 ],
Sean Condon98b6ddb2019-12-24 08:07:40 +0000162)