Sean Condon | 98b6ddb | 2019-12-24 08:07:40 +0000 | [diff] [blame] | 1 | """ |
| 2 | Copyright 2020-present Open Networking Foundation |
Sean Condon | 98b6ddb | 2019-12-24 08:07:40 +0000 | [diff] [blame] | 3 | 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 Condon | 98b6ddb | 2019-12-24 08:07:40 +0000 | [diff] [blame] | 6 | http://www.apache.org/licenses/LICENSE-2.0 |
Sean Condon | 98b6ddb | 2019-12-24 08:07:40 +0000 | [diff] [blame] | 7 | 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 | |
| 14 | package(default_visibility = ["//:__subpackages__"]) |
| 15 | |
| 16 | load("@build_bazel_rules_nodejs//:index.bzl", "pkg_web") |
Sean Condon | 98b6ddb | 2019-12-24 08:07:40 +0000 | [diff] [blame] | 17 | load("@npm//history-server:index.bzl", "history_server") |
Sean Condon | 436c60a | 2021-01-01 14:23:29 +0000 | [diff] [blame] | 18 | load("@npm//@bazel/rollup:index.bzl", "rollup_bundle") |
| 19 | load("@npm//@bazel/terser:index.bzl", "terser_minified") |
| 20 | load("@npm//@bazel/typescript:index.bzl", "ts_library") |
Sean Condon | 98b6ddb | 2019-12-24 08:07:40 +0000 | [diff] [blame] | 21 | |
Sean Condon | a3ad779 | 2020-01-04 19:26:34 +0000 | [diff] [blame] | 22 | exports_files([ |
| 23 | "WEB-INF/web.xml", |
Sean Condon | f86cfc9 | 2020-04-14 15:10:03 +0100 | [diff] [blame] | 24 | "karma.conf.js", |
Sean Condon | a3ad779 | 2020-01-04 19:26:34 +0000 | [diff] [blame] | 25 | ]) |
Sean Condon | 98b6ddb | 2019-12-24 08:07:40 +0000 | [diff] [blame] | 26 | |
| 27 | # We don't import from these, but the generated ngfactory code will |
| 28 | NG_FACTORY_ADDED_IMPORTS = [ |
| 29 | "@npm//@angular/animations", |
| 30 | "@npm//@angular/forms", |
| 31 | ] |
| 32 | |
Sean Condon | 436c60a | 2021-01-01 14:23:29 +0000 | [diff] [blame] | 33 | ts_library( |
Sean Condon | 98b6ddb | 2019-12-24 08:07:40 +0000 | [diff] [blame] | 34 | name = "gui2", |
| 35 | srcs = [ |
| 36 | "environments/environment.prod.ts", |
Sean Condon | a3ad779 | 2020-01-04 19:26:34 +0000 | [diff] [blame] | 37 | "onos.dev.ts", |
Sean Condon | 98b6ddb | 2019-12-24 08:07:40 +0000 | [diff] [blame] | 38 | "onos.prod.ts", |
| 39 | ], |
Sean Condon | a3ad779 | 2020-01-04 19:26:34 +0000 | [diff] [blame] | 40 | tsconfig = "//web/gui2:tsconfig.json", |
Sean Condon | 436c60a | 2021-01-01 14:23:29 +0000 | [diff] [blame] | 41 | use_angular_plugin = True, |
Sean Condon | 98b6ddb | 2019-12-24 08:07:40 +0000 | [diff] [blame] | 42 | 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 | |
| 50 | rollup_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 Condon | 436c60a | 2021-01-01 14:23:29 +0000 | [diff] [blame] | 59 | "@npm//@rollup/plugin-commonjs", |
| 60 | "@npm//@rollup/plugin-node-resolve", |
Sean Condon | 98b6ddb | 2019-12-24 08:07:40 +0000 | [diff] [blame] | 61 | ], |
| 62 | ) |
| 63 | |
| 64 | terser_minified( |
| 65 | name = "bundle-es2015.min", |
| 66 | src = ":bundle-es2015", |
Sean Condon | 436c60a | 2021-01-01 14:23:29 +0000 | [diff] [blame] | 67 | config_file = "terser.config.json", |
Sean Condon | 98b6ddb | 2019-12-24 08:07:40 +0000 | [diff] [blame] | 68 | ) |
| 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 | |
| 93 | pkg_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 Condon | a3ad779 | 2020-01-04 19:26:34 +0000 | [diff] [blame] | 100 | ":index.html", |
Sean Condon | 98b6ddb | 2019-12-24 08:07:40 +0000 | [diff] [blame] | 101 | ], |
| 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 | |
| 109 | history_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 Condon | a3ad779 | 2020-01-04 19:26:34 +0000 | [diff] [blame] | 122 | filegroup( |
| 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 Condon | 98b6ddb | 2019-12-24 08:07:40 +0000 | [diff] [blame] | 131 | genrule( |
Sean Condon | a3ad779 | 2020-01-04 19:26:34 +0000 | [diff] [blame] | 132 | 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 | |
| 144 | ts_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 Condon | 98b6ddb | 2019-12-24 08:07:40 +0000 | [diff] [blame] | 156 | ) |