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", |
Sean Condon | f86cfc9 | 2020-04-14 15:10:03 +0100 | [diff] [blame] | 32 | "karma.conf.js", |
Sean Condon | a3ad779 | 2020-01-04 19:26:34 +0000 | [diff] [blame] | 33 | ]) |
Sean Condon | 98b6ddb | 2019-12-24 08:07:40 +0000 | [diff] [blame] | 34 | |
| 35 | # We don't import from these, but the generated ngfactory code will |
| 36 | NG_FACTORY_ADDED_IMPORTS = [ |
| 37 | "@npm//@angular/animations", |
| 38 | "@npm//@angular/forms", |
| 39 | ] |
| 40 | |
| 41 | ng_module( |
| 42 | name = "gui2", |
| 43 | srcs = [ |
| 44 | "environments/environment.prod.ts", |
Sean Condon | a3ad779 | 2020-01-04 19:26:34 +0000 | [diff] [blame] | 45 | "onos.dev.ts", |
Sean Condon | 98b6ddb | 2019-12-24 08:07:40 +0000 | [diff] [blame] | 46 | "onos.prod.ts", |
| 47 | ], |
Sean Condon | a3ad779 | 2020-01-04 19:26:34 +0000 | [diff] [blame] | 48 | tsconfig = "//web/gui2:tsconfig.json", |
Sean Condon | 98b6ddb | 2019-12-24 08:07:40 +0000 | [diff] [blame] | 49 | 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 | |
| 57 | rollup_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 | |
| 71 | terser_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 | |
| 99 | pkg_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 Condon | a3ad779 | 2020-01-04 19:26:34 +0000 | [diff] [blame] | 106 | ":index.html", |
Sean Condon | 98b6ddb | 2019-12-24 08:07:40 +0000 | [diff] [blame] | 107 | ], |
| 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 | |
| 115 | history_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 Condon | a3ad779 | 2020-01-04 19:26:34 +0000 | [diff] [blame] | 128 | filegroup( |
| 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 Condon | 98b6ddb | 2019-12-24 08:07:40 +0000 | [diff] [blame] | 137 | genrule( |
Sean Condon | a3ad779 | 2020-01-04 19:26:34 +0000 | [diff] [blame] | 138 | 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 | |
| 150 | ts_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 Condon | 98b6ddb | 2019-12-24 08:07:40 +0000 | [diff] [blame] | 162 | ) |