grpc-protobufjs-devtools
插件介绍
grpc、proto、protobufjs、devtools、chrome、扩展
### 使用
1、使用node和protobufjs创建proto.js。
``` JavaScript
const pbjs = require("protobufjs/cli/pbjs");
const fs = require('fs');
const 路径 = require('路径');
const glob = require('glob');
const protoPath = 'src/proto/**/*.proto'; // 原始路径
const protos = glob.sync(protoPath);
pbjs.main([ "--target", "json-module", "-w", "commonjs", ...protos], 函数(err, 输出) {
如果(错误)
抛出错误;
// 目标路径
fs.writeFileSync(path.resolve(__dirname, './src/xxx/proto.js'), 输出);
});
````
2、挂载json字符串到窗口。
``` JavaScript
const $root = require('./src/xxx/proto.js');
window.__DEVTOOLS_PROTO_JSON_STRING__ = JSON.stringify($root.toJSON({keepComments: true}));
````