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") |
| 22 | load("@npm_angular_bazel//:index.bzl", "ng_module") |
| 23 | load("@npm_bazel_rollup//:index.bzl", "rollup_bundle") |
| 24 | load("@npm_bazel_terser//:index.bzl", "terser_minified") |
| 25 | load("@npm_bazel_typescript//:index.bzl", "ts_config", "ts_devserver", "ts_library") |
| 26 | |
| 27 | #load("@npm_bazel_karma//:index.bzl", "ts_web_test_suite") |
| 28 | |
| 29 | exports_files(["WEB-INF/web.xml"]) |
| 30 | |
| 31 | # We don't import from these, but the generated ngfactory code will |
| 32 | NG_FACTORY_ADDED_IMPORTS = [ |
| 33 | "@npm//@angular/animations", |
| 34 | "@npm//@angular/forms", |
| 35 | ] |
| 36 | |
| 37 | ng_module( |
| 38 | name = "gui2", |
| 39 | srcs = [ |
| 40 | "environments/environment.prod.ts", |
| 41 | "onos.prod.ts", |
| 42 | ], |
| 43 | tsconfig = "//:tsconfig.json", |
| 44 | deps = NG_FACTORY_ADDED_IMPORTS + [ |
| 45 | "//web/gui2/src/main/webapp/app:app", |
| 46 | "@npm//@angular/core", |
| 47 | "@npm//@angular/platform-browser", |
| 48 | "@npm//@angular/router", |
| 49 | ], |
| 50 | ) |
| 51 | |
| 52 | rollup_bundle( |
| 53 | name = "bundle-es2015", |
| 54 | config_file = "rollup.config.js", |
| 55 | entry_points = { |
| 56 | ":onos.prod.ts": "index", |
| 57 | }, |
| 58 | output_dir = True, |
| 59 | deps = [ |
| 60 | "//web/gui2/src/main/webapp:gui2", |
| 61 | "@npm//rollup-plugin-commonjs", |
| 62 | "@npm//rollup-plugin-node-resolve", |
| 63 | ], |
| 64 | ) |
| 65 | |
| 66 | terser_minified( |
| 67 | name = "bundle-es2015.min", |
| 68 | src = ":bundle-es2015", |
| 69 | ) |
| 70 | |
| 71 | # Files that we serve in both development and production |
| 72 | _ASSETS = [ |
| 73 | # This label references an output of the "styles" sass_binary above. |
| 74 | ":onos.global.css", |
| 75 | "//web/gui:src/main/webapp/data", |
| 76 | "fonts/open-sans-v15-latin-300.woff", |
| 77 | "fonts/open-sans-v15-latin-300.woff2", |
| 78 | "fonts/open-sans-v15-latin-600.woff", |
| 79 | "fonts/open-sans-v15-latin-600.woff2", |
| 80 | "fonts/open-sans-v15-latin-700.woff", |
| 81 | "fonts/open-sans-v15-latin-700.woff2", |
| 82 | "error.html", |
| 83 | "login.html", |
| 84 | "nav.html", |
| 85 | "not-ready.html", |
| 86 | # We load zone.js outside the bundle. That's because it's a "pollyfill" |
| 87 | # which speculates that such features might be available in a browser. |
| 88 | # Also it's tricky to configure dead code elimination to understand that |
| 89 | # zone.js is used, given that we don't have any import statement that |
| 90 | # imports from it. |
| 91 | "@npm//:node_modules/zone.js/dist/zone.min.js", |
| 92 | ] |
| 93 | |
| 94 | pkg_web( |
| 95 | name = "prodapp", |
| 96 | srcs = _ASSETS + [ |
| 97 | ":bundle-es2015.min", |
| 98 | # Include polyfills that will be requested by old browsers |
| 99 | # "@npm//:node_modules/systemjs/dist/system.js", |
| 100 | # "@npm//:node_modules/core-js/client/core.min.js", |
| 101 | "index.html", |
| 102 | ], |
| 103 | # In production mode we serve some polyfills with script tags that have hard-coded paths in the index.html |
| 104 | # so we must serve them at that path, by stripping a prefix |
| 105 | additional_root_paths = [ |
| 106 | "web/gui/src/main/webapp", |
| 107 | ], |
| 108 | ) |
| 109 | |
| 110 | history_server( |
| 111 | name = "prodserver", |
| 112 | data = [":prodapp"], |
| 113 | # '-a src/prodapp' will ask history-server to scan for all apps under the |
| 114 | # given folder this will result in the following auto-configuration: |
| 115 | # /example => src/prodapp/example |
| 116 | # / => src/prodapp |
| 117 | templated_args = [ |
| 118 | "-a", |
| 119 | "web/gui2/src/main/webapp/prodapp", |
| 120 | ], |
| 121 | ) |
| 122 | |
| 123 | genrule( |
| 124 | name = "d3-copy", |
| 125 | srcs = ["@npm//:node_modules/d3/dist/d3.js"], |
| 126 | outs = ["d3.js"], |
| 127 | cmd = "cp $< $@", |
| 128 | output_to_bindir = 1, |
| 129 | ) |