This package contains experimental code which isn't at the same quality or stability standard as our main packages.
By using code in Labs, we trust that you understand:
USAGE
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", ], )
ATTRIBUTES
(Name, mandatory): A unique name for this target.
(List of labels): proto_library targets
Defaults to []
(String): Name of the resulting module, which you will import from. If not specified, the name will match the target's name.
Defaults to ""
USAGE
ATTRIBUTES
(Name, mandatory): A unique name for this target.
(Label, mandatory) The dependencies of this attribute must provide: ProtoInfo