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