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

 

  

posted on 2020-12-09 17:52  青叶煮酒  阅读(1479)  评论(0编辑  收藏  举报