通过 protoc-gen-grpc-web 插件自动生成 gPRC 服务接口的 JavaScript 调用代码

1. 安装 protoc and protoc-gen-grpc-web 插件

  protoc 下载: https://github.com/protocolbuffers/protobuf/releases

  protoc-gen-grpc-web 插件下载: https://github.com/grpc/grpc-web/releases

2. 将 protoc and protoc-gen-grpc-web 安装目录的 Bin 添加到系统环境变量

3. 打开 CMD 切换目录到 gRPC 的 xxx.proto 下

  运行如下命令,生成对应的 xxx_grpc_web_pb.js 和 xxx_pb.js 文件:

protoc -I=. xxx.proto --js_out=import_style=commonjs:. --grpc-web_out=import_style=commonjs,mode=grpcwebtext:.

参考:https://github.com/grpc/grpc-web/tree/master/net/grpc/gateway/examples/helloworld#generate-protobuf-messages-and-client-service-stub

  

原文地址:https://www.cnblogs.com/dhqy/p/14110029.html