mirror of
https://gitee.com/270580156/weiyu.git
synced 2025-12-30 10:52:26 +00:00
Proto 说明
兼容es6步骤
-
npm install -g protoc-gen-js
-
protoc --js_out=import_style=es6,binary:. message.proto thread.proto user.proto
-
修改message_pb.js
顶部添加下面代码
import * as jspb from "google-protobuf";
var goog = jspb;
var global = function () {
if (this) {
return this;
}
if (typeof window !== "undefined") {
return window;
}
if (typeof global !== "undefined") {
return global;
}
if (typeof self !== "undefined") {
return self;
}
return Function("return this")();
}.call(null);
import { default as User } from "./user_pb.js";
import { default as Thread } from "./thread_pb.js";
最底部添加如下代码
export default proto;
- 修改thread_pb.js和user_pb.js, 顶部添加如下代码
import * as jspb from "google-protobuf";
var goog = jspb;
var global = function () {
if (this) {
return this;
}
if (typeof window !== "undefined") {
return window;
}
if (typeof global !== "undefined") {
return global;
}
if (typeof self !== "undefined") {
return self;
}
return Function("return this")();
}.call(null);
最底部添加如下代码
export default proto;
- 导入到mqtt.js
import { default as messageProto } from "./protobuf/message_pb.js";