Public API surface is re-exported here.
Rules
protobufjs_ts_library
Wraps https://github.com/dcodeIO/protobuf.js for use in Bazel.
ts_proto_library
has identical outputs to ts_library
, so it can be used anywhere
a ts_library
can appear, such as in the deps[]
of another ts_library
.
Example:
load("@npm//@bazel/typescript:index.bzl", "ts_library", "ts_proto_library")
proto_library(
name = "car_proto",
srcs = ["car.proto"],
)
ts_proto_library(
name = "car",
deps = [":car_proto"],
)
ts_library(
name = "test_lib",
testonly = True,
srcs = ["car.spec.ts"],
deps = [":car"],
)
Note in this example we named the ts_proto_library
rule car
so that the
result will be car.d.ts
. This means our TypeScript code can just
import {symbols} from './car'
. Use the output_name
attribute if you want to
name the rule differently from the output file.
The JavaScript produced by protobuf.js has a runtime dependency on a support library.
Under devmode (e.g. ts_devserver
, karma_web_test_suite
) you'll need to include these scripts
in the bootstrap
phase (before Require.js loads). You can use the label
@npm//@bazel/labs/protobufjs:bootstrap_scripts
to reference these scripts
in the bootstrap
attribute of karma_web_test_suite
or ts_devserver
.
To complete the example above, you could write a karma_web_test_suite
:
load("@npm//@bazel/karma:index.bzl", "karma_web_test_suite")
karma_web_test_suite(
name = "test",
deps = ["test_lib"],
bootstrap = ["@npm//@bazel/labs/protobufjs:bootstrap_scripts"],
browsers = [
"@io_bazel_rules_webtesting//browsers:chromium-local",
"@io_bazel_rules_webtesting//browsers:firefox-local",
],
)
name
A unique name for this target.
deps
proto_library targets
output_name
Name of the resulting module, which you will import from. If not specified, the name will match the target's name.
ts_proto_library
name
A unique name for this target.