Sean Condon | 98b6ddb | 2019-12-24 08:07:40 +0000 | [diff] [blame] | 1 | """ |
| 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 | |
| 17 | package(default_visibility = ["//:__subpackages__"]) |
| 18 | |
| 19 | load("@build_bazel_rules_nodejs//:index.bzl", "pkg_web") |
| 20 | load("@io_bazel_rules_sass//:defs.bzl", "sass_binary") |
| 21 | load("@npm//history-server:index.bzl", "history_server") |
Sean Condon | a3ad779 | 2020-01-04 19:26:34 +0000 | [diff] [blame] | 22 | load("@npm//html-insert-assets:index.bzl", "html_insert_assets") |
Sean Condon | 98b6ddb | 2019-12-24 08:07:40 +0000 | [diff] [blame] | 23 | load("@npm_angular_bazel//:index.bzl", "ng_module") |
| 24 | load("@npm_bazel_rollup//:index.bzl", "rollup_bundle") |
| 25 | load("@npm_bazel_terser//:index.bzl", "terser_minified") |
| 26 | load("@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 Condon | a3ad779 | 2020-01-04 19:26:34 +0000 | [diff] [blame] | 30 | exports_files([ |
| 31 | "WEB-INF/web.xml", |
| 32 | ]) |
Sean Condon | 98b6ddb | 2019-12-24 08:07:40 +0000 | [diff] [blame] | 33 | |
| 34 | # We don't import from these, but the generated ngfactory code will |
| 35 | NG_FACTORY_ADDED_IMPORTS = [ |
| 36 | "@npm//@angular/animations", |
| 37 | "@npm//@angular/forms", |
| 38 | ] |
| 39 | |
| 40 | ng_module( |
| 41 | name = "gui2", |
| 42 | srcs = [ |
| 43 | "environments/environment.prod.ts", |
Sean Condon | a3ad779 | 2020-01-04 19:26:34 +0000 | [diff] [blame] | 44 | "onos.dev.ts", |
Sean Condon | 98b6ddb | 2019-12-24 08:07:40 +0000 | [diff] [blame] | 45 | "onos.prod.ts", |
| 46 | ], |
Sean Condon | a3ad779 | 2020-01-04 19:26:34 +0000 | [diff] [blame] | 47 | tsconfig = "//web/gui2:tsconfig.json", |
Sean Condon | 98b6ddb | 2019-12-24 08:07:40 +0000 | [diff] [blame] | 48 | 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 | |
| 56 | rollup_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 | |
| 70 | terser_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 | |
| 98 | pkg_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 Condon | a3ad779 | 2020-01-04 19:26:34 +0000 | [diff] [blame] | 105 | ":index.html", |
Sean Condon | 98b6ddb | 2019-12-24 08:07:40 +0000 | [diff] [blame] | 106 | ], |
| 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 | |
| 114 | history_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 Condon | a3ad779 | 2020-01-04 19:26:34 +0000 | [diff] [blame] | 127 | filegroup( |
| 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 Condon | 98b6ddb | 2019-12-24 08:07:40 +0000 | [diff] [blame] | 136 | genrule( |
Sean Condon | a3ad779 | 2020-01-04 19:26:34 +0000 | [diff] [blame] | 137 | 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 | |
| 149 | ts_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 Condon | 98b6ddb | 2019-12-24 08:07:40 +0000 | [diff] [blame] | 161 | ) |