Documentation for @aspect_rules_js@v3.0.2 — View source
Typical setup
- Choose any code generator plugin for protoc.
In this example we’ll show
@bufbuild/protoc-gen-esthat produces both message marshaling and service stubs for JavaScript and TypeScript. It should be added as a devDependency in yourpackage.json, typically under a/toolsdirectory. The generator is expected to produce.jsand.d.tsfiles for each .proto file. - Declare a binary target that runs the generator, typically using its package_json.bzl entry point, for example in
tools/toolchains/BUILD:
- Define a
js_proto_toolchainthat uses the plugin. See the rule documentation below. - Update
MODULE.bazelto register it, typically with a simple statement likeregister_toolchains("//tools/toolchains:all")
Usage
Just writeproto_library targets as usual, or have Gazelle generate them.
Then reference them anywhere a js_library could appear, for example:
.js and .d.ts files.
Function: js_proto_toolchain
Define a proto_lang_toolchain that uses the plugin.
Example:
Parameters
The name of the toolchain. A target named [name]_toolchain is also created, which is the one to be used in register_toolchains.
The
NAME of the plugin program, used in command-line flags to protoc, as follows:
protoc --plugin=protoc-gen-NAME=path/to/mybinary --NAME_out=OUT_DIR
See https://protobuf.dev/reference/cpp/api-docs/google.protobuf.compiler.plugin(List of strings) Command line flags used to invoke the plugin, based on documentation for the generator.For example, for
@bufbuild/protoc-gen-es, reference the documentation at
https://github.com/bufbuild/protobuf-es/tree/main/packages/protoc-gen-es#plugin-options
to arrive at a value like ["import_extension=js"]The plugin to use. This should be the label of a binary target that you declared in step 2 above.
The runtime to use, which is imported by the generated code. For example, ”//:node_modules/@bufbuild/protobuf”.Note that node module resolution requires the runtime to be in a parent folder of any package containing generated code.
Additional arguments to pass to the proto_lang_toolchain rule.

