blob: 9d211cd2579c7f10abeb68b240f071b9cd449df5 [file]
# Add rules here to build your software
# See https://docs.bazel.build/versions/master/build-ref.html#BUILD_files
load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin", "pkg_web")
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_js_import", "kt_js_library")
load("@npm//@bazel/jasmine:index.bzl", "jasmine_node_test")
load("@npm//@bazel/rollup:index.bzl", "rollup_bundle")
load("@npm//@bazel/terser:index.bzl", "terser_minified")
load("@npm//http-server:index.bzl", "http_server")
# Grab a Maven dependency
kt_js_import(
name = "kotlinx-html-js",
jars = ["@maven//:v1/http/dl.bintray.com/kotlin/kotlinx.html/org/jetbrains/kotlinx/kotlinx-html-js/0.6.12/kotlinx-html-js-0.6.12.jar"],
srcjar = "@maven//:v1/http/dl.bintray.com/kotlin/kotlinx.html/org/jetbrains/kotlinx/kotlinx-html-js/0.6.12/kotlinx-html-js-0.6.12-sources.jar",
)
# This will create hello.js
kt_js_library(
name = "hello",
srcs = [":HelloWorld.kt"],
deps = [":kotlinx-html-js"],
)
# Copy bootstrap.js to the output folder, so all files are next to each other at runtime
# Allows the `./hello.js` relative import to work while referencing an output file
copy_to_bin(
name = "bootstrap",
srcs = ["bootstrap.js"],
)
rollup_bundle(
name = "bundle",
srcs = ["hello.js"],
config_file = "rollup.config.js",
# Reference the copy of bootstrap.js in the output folder
entry_point = "bootstrap",
# TODO: make this example work with format = "esm"
format = "cjs",
output_dir = True,
deps = [
"@npm//@rollup/plugin-commonjs",
"@npm//@rollup/plugin-node-resolve",
"@npm//kotlin",
"@npm//kotlinx-html-js",
],
)
terser_minified(
# This will output bundle.min directory since rollup produces a directory
name = "bundle.min",
src = ":bundle",
)
pkg_web(
name = "package",
srcs = [
"bundle.min",
"index.html",
],
)
# TODO: fix prodserver; require.js is needed if rollup_bundle output is cjs
http_server(
name = "server",
data = [":package"],
templated_args = ["package"],
)
jasmine_node_test(
name = "test",
srcs = ["spec.js"],
data = [
":bundle",
"@npm//domino",
],
templated_args = [
# TODO: don't rely on patching require()
"--bazel_patch_module_resolver",
"--node_options=--experimental-modules",
],
)