Skip to content

Instantly share code, notes, and snippets.

@afifalfiano
Created June 14, 2020 01:07
Show Gist options
  • Save afifalfiano/ffbea4d0c2d3ac3f55f513528c1a1f3a to your computer and use it in GitHub Desktop.
Save afifalfiano/ffbea4d0c2d3ac3f55f513528c1a1f3a to your computer and use it in GitHub Desktop.
File lengkap
package(default_visibility = ["//visibility:public"])
load("@build_bazel_rules_nodejs//:index.bzl", "pkg_web")
load("@npm//history-server:index.bzl", "history_server")
load("@npm//html-insert-assets:index.bzl", "html_insert_assets")
load("@npm_angular_bazel//:index.bzl", "ng_module")
load("@npm_bazel_karma//:index.bzl", "karma_web_test_suite")
load("@npm_bazel_rollup//:index.bzl", "rollup_bundle")
load("@npm_bazel_terser//:index.bzl", "terser_minified")
load("@npm_bazel_typescript//:index.bzl", "ts_devserver", "ts_library")
load("@io_bazel_rules_sass//:defs.bzl", "multi_sass_binary", "sass_binary")
sass_binary(
name = "global_stylesheet",
src = glob(["styles.css", "styles.scss"])[0],
output_name = "global_stylesheet.css",
)
multi_sass_binary(
name = "styles",
srcs = glob(
include = ["**/*.scss"],
exclude = ["styles.scss"],
),
)
ng_module(
name = "src",
srcs = glob(
include = ["**/*.ts"],
exclude = [
"**/*.spec.ts",
"main.ts",
"test.ts",
"initialize_testbed.ts",
],
),
assets = glob([
"**/*.css",
"**/*.html",
]) + ([":styles"] if len(glob(["**/*.scss"])) else []),
generate_ve_shims = True,
deps = [
"@npm//@angular/core",
"@npm//@angular/platform-browser",
"@npm//@angular/router",
"@npm//@types",
"@npm//rxjs",
],
)
rollup_bundle(
name = "bundle",
config_file = "rollup.config.js",
entry_point = ":main.prod.ts",
deps = [
"//src",
"@npm//rollup-plugin-commonjs",
"@npm//rollup-plugin-node-resolve",
],
)
terser_minified(
name = "bundle.min",
src = ":bundle",
)
html_insert_assets(
name = "asset_injected_index_html",
outs = ["_/index.html"],
args = [
"--html",
"$(execpath :index.html)",
"--out",
"$@",
"--roots",
"$(RULEDIR)",
"--assets",
"$(execpath :global_stylesheet.css)",
"$(execpath @npm//:node_modules/zone.js/dist/zone.min.js)",
"bundle.min.js",
],
data = [
":index.html",
":global_stylesheet.css",
"@npm//:node_modules/zone.js/dist/zone.min.js",
],
)
pkg_web(
name = "prodapp",
additional_root_paths = ["src/_"],
srcs = [
"@npm//:node_modules/zone.js/dist/zone.min.js",
":bundle.min",
":global_stylesheet",
":asset_injected_index_html",
"favicon.ico",
],
)
history_server(
name = "prodserver",
data = [":prodapp"],
args = [
"--port",
"4200",
],
templated_args = ["$(rlocation project/src/prodapp)"],
)
filegroup(
name = "rxjs_umd_modules",
srcs = [
# do not sort
"@npm//:node_modules/rxjs/bundles/rxjs.umd.js",
":rxjs_shims.js",
],
)
ts_devserver(
name = "devserver",
additional_root_paths = ["project/src/_"],
port = 4200,
entry_module = "project/src/main.dev",
serving_path = "/bundle.min.js",
scripts = [
"@npm//:node_modules/tslib/tslib.js",
":rxjs_umd_modules",
],
static_files = [
"@npm//:node_modules/zone.js/dist/zone.min.js",
":global_stylesheet",
":asset_injected_index_html",
"favicon.ico",
],
deps = [":src"],
)
ts_library(
name = "test_lib",
testonly = 1,
srcs = glob(["**/*.spec.ts"]),
deps = [
":src",
"@npm//@angular/core",
"@npm//@angular/router",
"@npm//@types",
],
)
ts_library(
name = "initialize_testbed",
testonly = 1,
srcs = [
"initialize_testbed.ts",
],
deps = [
"@npm//@angular/core",
"@npm//@angular/platform-browser-dynamic",
"@npm//@types",
],
)
karma_web_test_suite(
name = "test",
srcs = [
"@npm//:node_modules/tslib/tslib.js",
],
runtime_deps = [
":initialize_testbed",
],
# do not sort
bootstrap = [
"@npm//:node_modules/zone.js/dist/zone-testing-bundle.js",
"@npm//:node_modules/reflect-metadata/Reflect.js",
],
browsers = [
"@io_bazel_rules_webtesting//browsers:chromium-local",
],
tags = ["native"],
deps = [
":rxjs_umd_modules",
":test_lib",
],
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment