Webpack loader for .proto files
- to be used along with mapbox/pbf
- uses protocol-buffers-schema as schema parser
- returns a compiled module ready to be used when you
require('./file.proto')
Installation
npm install pbf-loader
Usage
see example for sample implementation.
Given your webpack.config.js
like this:
moduleexports = module: loaders: test: /\.proto$/ loader: "pbf-loader"
Instead of:
const Pbf = ; const compile = ;const fs = ;const schema = ; const data = 'somestring';const proto = schema;const test = test; // assuming message definition: message test {}
using this webpack loader, simply require your .proto file like this:
const proto = ;const Pbf = ; const data = "somestring"; // data that you want to write; const schema = prototest; // accessing the message definitionconst pbf = ; // now you can write data to your pbf with pbf.writeMessage etc.pbf;const buffer = pbf;// now you can read back your message using schema.read(new Pbf(buffer))
You can refer to index.proto for how the .proto file looks like.
Test
Assuming you already did npm install
, you can:
npm test
License
This project is released under the terms of the Apache 2.0 license.