构建

英文原地址

要自己构建库或其组件,可以从 GitHub 克隆它并安装开发依赖项:

$> git clone https://github.com/dcodeIO/protobuf.js.git
$> cd protobuf.js
$> npm install
1
2
3

构建相应的开发和生产版本,并将它们的 source map 发送到dist/:

$> npm run build
1

构建文档至docs/

$> npm run docs
1

构建 TypeScript 的类型文件index.d.ts

$> npm run types
1

浏览器集成

默认情况下,protobuf.js会集成到任何的browserify构建过程中,而无需任何其他模块。因此:

  • 如果需要 int64 支持,那就需要在项目中的某个地方使用long模块,否则它会被排除在外的。这里我们假设存在一个全局的require函数,protobuf.js可以调用该函数来获得long模块。
    如果绑定后没有全局require函数,也可以手动分配long模块:
var Long = ...;

protobuf.util.Long = Long;
protobuf.configure();
1
2
3
4
  • 如果您有任何特殊要求,请参考这里