build: serve ivy todo app with real http-server (#23446)

PR Close #23446
This commit is contained in:
Alex Eagle 2018-04-16 14:55:47 -07:00 committed by Igor Minar
parent db77d8dc92
commit b4c252bcc5
13 changed files with 202 additions and 36 deletions

View File

@ -96,11 +96,11 @@ jobs:
path: dist/bin/packages/core/test/bundling/todo/bundle.min.js path: dist/bin/packages/core/test/bundling/todo/bundle.min.js
destination: packages/core/test/bundling/todo/bundle.min.js destination: packages/core/test/bundling/todo/bundle.min.js
- store_artifacts: - store_artifacts:
path: dist/bin/packages/core/test/bundling/hello_world/bundle.min.js.brotli path: dist/bin/packages/core/test/bundling/hello_world/bundle.min.js.br
destination: packages/core/test/bundling/hello_world/bundle.min.js.brotli destination: packages/core/test/bundling/hello_world/bundle.min.js.br
- store_artifacts: - store_artifacts:
path: dist/bin/packages/core/test/bundling/todo/bundle.min.js.brotli path: dist/bin/packages/core/test/bundling/todo/bundle.min.js.br
destination: packages/core/test/bundling/todo/bundle.min.js.brotli destination: packages/core/test/bundling/todo/bundle.min.js.br
- save_cache: - save_cache:
key: *cache_key key: *cache_key

View File

@ -18,6 +18,12 @@ yarn_install(
yarn_lock = "//tools/ts-api-guardian:yarn.lock", yarn_lock = "//tools/ts-api-guardian:yarn.lock",
) )
yarn_install(
name = "http-server_runtime_deps",
package_json = "//tools/http-server:package.json",
yarn_lock = "//tools/http-server:yarn.lock",
)
http_archive( http_archive(
name = "build_bazel_rules_typescript", name = "build_bazel_rules_typescript",
url = "https://github.com/bazelbuild/rules_typescript/archive/0.12.1.zip", url = "https://github.com/bazelbuild/rules_typescript/archive/0.12.1.zip",

View File

@ -83,6 +83,6 @@ ng_rollup_bundle = rule(
default = Label("@org_brotli//:brotli")), default = Label("@org_brotli//:brotli")),
}), }),
outputs = dict(ROLLUP_OUTPUTS, **{ outputs = dict(ROLLUP_OUTPUTS, **{
"build_es5_min_compressed": "%{name}.min.js.brotli", "build_es5_min_compressed": "%{name}.min.js.br",
}), }),
) )

View File

@ -4,7 +4,7 @@ load("//tools:defaults.bzl", "ts_library", "ivy_ng_module")
load("//tools/symbol-extractor:index.bzl", "js_expected_symbol_test") load("//tools/symbol-extractor:index.bzl", "js_expected_symbol_test")
load("//packages/bazel/src:ng_rollup_bundle.bzl", "ng_rollup_bundle") load("//packages/bazel/src:ng_rollup_bundle.bzl", "ng_rollup_bundle")
load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test") load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_devserver") load("//tools/http-server:http_server.bzl", "http_server")
ivy_ng_module( ivy_ng_module(
name = "hello_world", name = "hello_world",
@ -44,7 +44,7 @@ jasmine_node_test(
data = [ data = [
":bundle", ":bundle",
":bundle.js", ":bundle.js",
":bundle.min.js.brotli", ":bundle.min.js.br",
":bundle.min_debug.js", ":bundle.min_debug.js",
], ],
deps = [":test_lib"], deps = [":test_lib"],
@ -56,12 +56,11 @@ js_expected_symbol_test(
golden = ":bundle.golden_symbols.json", golden = ":bundle.golden_symbols.json",
) )
ts_devserver( http_server(
name = "devserver", name = "devserver",
static_files = [ data = [
":bundle.min_debug.js",
":bundle.min.js",
"index.html", "index.html",
":bundle.min.js",
":bundle.min_debug.js",
], ],
deps = [],
) )

View File

@ -2,7 +2,7 @@ package(default_visibility = ["//visibility:public"])
load("//tools:defaults.bzl", "ts_library", "ivy_ng_module") load("//tools:defaults.bzl", "ts_library", "ivy_ng_module")
load("//packages/bazel/src:ng_rollup_bundle.bzl", "ng_rollup_bundle") load("//packages/bazel/src:ng_rollup_bundle.bzl", "ng_rollup_bundle")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_devserver") load("//tools/http-server:http_server.bzl", "http_server")
ivy_ng_module( ivy_ng_module(
name = "hello_world_i18n", name = "hello_world_i18n",
@ -27,12 +27,11 @@ ng_rollup_bundle(
], ],
) )
ts_devserver( http_server(
name = "devserver", name = "prodserver",
static_files = [ data = [
":bundle.min_debug.js",
":bundle.min.js",
"index.html", "index.html",
":bundle.min.js",
":bundle.min_debug.js",
], ],
deps = [],
) )

View File

@ -4,7 +4,7 @@ load("//tools:defaults.bzl", "ts_library", "ng_module")
load("//tools/symbol-extractor:index.bzl", "js_expected_symbol_test") load("//tools/symbol-extractor:index.bzl", "js_expected_symbol_test")
load("//packages/bazel/src:ng_rollup_bundle.bzl", "ng_rollup_bundle") load("//packages/bazel/src:ng_rollup_bundle.bzl", "ng_rollup_bundle")
load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test") load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_devserver") load("//tools/http-server:http_server.bzl", "http_server")
ng_module( ng_module(
name = "hello_world", name = "hello_world",
@ -46,7 +46,7 @@ jasmine_node_test(
data = [ data = [
":bundle", ":bundle",
":bundle.js", ":bundle.js",
":bundle.min.js.brotli", ":bundle.min.js.br",
":bundle.min_debug.js", ":bundle.min_debug.js",
], ],
deps = [":test_lib"], deps = [":test_lib"],
@ -58,12 +58,11 @@ js_expected_symbol_test(
golden = ":bundle.golden_symbols.json", golden = ":bundle.golden_symbols.json",
) )
ts_devserver( http_server(
name = "devserver", name = "prodserver",
static_files = [ data = [
":bundle.min_debug.js",
":bundle.min.js",
"index.html", "index.html",
":bundle.min.js",
":bundle.min_debug.js",
], ],
deps = [],
) )

View File

@ -1,6 +1,7 @@
package(default_visibility = ["//visibility:public"]) package(default_visibility = ["//visibility:public"])
load("//tools:defaults.bzl", "ts_library", "ivy_ng_module") load("//tools:defaults.bzl", "ts_library", "ivy_ng_module")
load("//tools/http-server:http_server.bzl", "http_server")
load("//tools/symbol-extractor:index.bzl", "js_expected_symbol_test") load("//tools/symbol-extractor:index.bzl", "js_expected_symbol_test")
load("//packages/bazel/src:ng_rollup_bundle.bzl", "ng_rollup_bundle") load("//packages/bazel/src:ng_rollup_bundle.bzl", "ng_rollup_bundle")
load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test") load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test")
@ -46,7 +47,7 @@ jasmine_node_test(
data = [ data = [
":bundle", ":bundle",
":bundle.js", ":bundle.js",
":bundle.min.js.brotli", ":bundle.min.js.br",
":bundle.min_debug.js", ":bundle.min_debug.js",
], ],
deps = [":test_lib"], deps = [":test_lib"],
@ -82,15 +83,13 @@ ts_devserver(
deps = [":todo"], deps = [":todo"],
) )
# Even though this is `ts_devserver` rule, we are using it as simple static server http_server(
# This is mostly broken for `ibazel`, use `:devserver` instead.
ts_devserver(
name = "prodserver", name = "prodserver",
static_files = [ data = [
":bundle.min_debug.js", "base.css",
":bundle.min.js",
"index.html", "index.html",
"todo.css", "todo.css",
"base.css", ":bundle.min.js.br",
":bundle.min_debug.js",
], ],
) )

View File

@ -35,7 +35,7 @@
--> -->
<script> <script>
document.write('<script src="' + document.write('<script src="' +
(document.location.search.endsWith('debug') ? '/bundle.min_debug.js' : '/bundle.min.js') + (document.location.search.endsWith('debug') ? '/bundle.min_debug.js' : '/bundle.min.js.br') +
'"></' + 'script>'); '"></' + 'script>');
</script> </script>
<script> <script>

View File

@ -0,0 +1 @@
# Marker this directory is a Bazel package.

View File

@ -0,0 +1,11 @@
# http-server
This is a simple Bazel wrapper around the http-server npm package.
A typical frontend project is served by a specific server.
For Angular's example applications, our needs are simple so we can just use http-server.
Real projects might need history-server (for router support) or even better a full-featured production server like express.
We modify http-server to support serving Brotli-compressed files, which end with a `.br` extension.
This is equivalent to gzip-compression support.
See https://github.com/alexeagle/http-server/commits/master which points to a modified ecstatic library.

View File

@ -0,0 +1,18 @@
"""Simple Bazel wrapper around npm http-server package.
See https://www.npmjs.com/package/http-server
"""
load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary")
def http_server(args = [], **kwargs):
# By default, we pass an argument pointing the http server to the
# package of the caller.
# This assumes there is an index.html in the package directory.
if not args:
args = [native.package_name()]
nodejs_binary(
node_modules = "@http-server_runtime_deps//:node_modules",
entry_point = "http-server/bin/http-server",
args = args,
**kwargs)

View File

@ -0,0 +1,9 @@
{
"name": "http_server",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"devDependencies": {
"http-server": "github:alexeagle/http-server#97205e945b69091606ed83aa0c8489e9ce65d282"
}
}

125
tools/http-server/yarn.lock Normal file
View File

@ -0,0 +1,125 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
async@^1.5.2:
version "1.5.2"
resolved "https://registry.yarnpkg.com/async/-/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a"
colors@1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/colors/-/colors-1.0.3.tgz#0433f44d809680fdeb60ed260f1b0c262e82a40b"
corser@~2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/corser/-/corser-2.0.1.tgz#8eda252ecaab5840dcd975ceb90d9370c819ff87"
debug@^2.2.0:
version "2.6.9"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"
dependencies:
ms "2.0.0"
"ecstatic@github:alexeagle/node-ecstatic#833f734497f72f8cf396f162f46ad48c56ddc4ca":
version "3.2.0"
resolved "https://codeload.github.com/alexeagle/node-ecstatic/tar.gz/833f734497f72f8cf396f162f46ad48c56ddc4ca"
dependencies:
he "^1.1.1"
mime "^1.4.1"
minimist "^1.1.0"
url-join "^2.0.2"
eventemitter3@1.x.x:
version "1.2.0"
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-1.2.0.tgz#1c86991d816ad1e504750e73874224ecf3bec508"
he@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/he/-/he-1.1.1.tgz#93410fd21b009735151f8868c2f271f3427e23fd"
http-proxy@^1.8.1:
version "1.16.2"
resolved "https://registry.yarnpkg.com/http-proxy/-/http-proxy-1.16.2.tgz#06dff292952bf64dbe8471fa9df73066d4f37742"
dependencies:
eventemitter3 "1.x.x"
requires-port "1.x.x"
"http-server@github:alexeagle/http-server#97205e945b69091606ed83aa0c8489e9ce65d282":
version "0.11.1"
resolved "https://codeload.github.com/alexeagle/http-server/tar.gz/97205e945b69091606ed83aa0c8489e9ce65d282"
dependencies:
colors "1.0.3"
corser "~2.0.0"
ecstatic "github:alexeagle/node-ecstatic#833f734497f72f8cf396f162f46ad48c56ddc4ca"
http-proxy "^1.8.1"
opener "~1.4.0"
optimist "0.6.x"
portfinder "^1.0.13"
union "~0.4.3"
mime@^1.4.1:
version "1.6.0"
resolved "https://registry.yarnpkg.com/mime/-/mime-1.6.0.tgz#32cd9e5c64553bd58d19a568af452acff04981b1"
minimist@0.0.8:
version "0.0.8"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d"
minimist@^1.1.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284"
minimist@~0.0.1:
version "0.0.10"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.10.tgz#de3f98543dbf96082be48ad1a0c7cda836301dcf"
mkdirp@0.5.x:
version "0.5.1"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
dependencies:
minimist "0.0.8"
ms@2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
opener@~1.4.0:
version "1.4.3"
resolved "https://registry.yarnpkg.com/opener/-/opener-1.4.3.tgz#5c6da2c5d7e5831e8ffa3964950f8d6674ac90b8"
optimist@0.6.x:
version "0.6.1"
resolved "https://registry.yarnpkg.com/optimist/-/optimist-0.6.1.tgz#da3ea74686fa21a19a111c326e90eb15a0196686"
dependencies:
minimist "~0.0.1"
wordwrap "~0.0.2"
portfinder@^1.0.13:
version "1.0.13"
resolved "https://registry.yarnpkg.com/portfinder/-/portfinder-1.0.13.tgz#bb32ecd87c27104ae6ee44b5a3ccbf0ebb1aede9"
dependencies:
async "^1.5.2"
debug "^2.2.0"
mkdirp "0.5.x"
qs@~2.3.3:
version "2.3.3"
resolved "https://registry.yarnpkg.com/qs/-/qs-2.3.3.tgz#e9e85adbe75da0bbe4c8e0476a086290f863b404"
requires-port@1.x.x:
version "1.0.0"
resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff"
union@~0.4.3:
version "0.4.6"
resolved "https://registry.yarnpkg.com/union/-/union-0.4.6.tgz#198fbdaeba254e788b0efcb630bc11f24a2959e0"
dependencies:
qs "~2.3.3"
url-join@^2.0.2:
version "2.0.5"
resolved "https://registry.yarnpkg.com/url-join/-/url-join-2.0.5.tgz#5af22f18c052a000a48d7b82c5e9c2e2feeda728"
wordwrap@~0.0.2:
version "0.0.3"
resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-0.0.3.tgz#a3d5da6cd5c0bc0008d37234bbaf1bed63059107"