protobuf.js
protobuf.js copied to clipboard
cli: how to generate static code only for necessary types?
protobuf.js version: 7.0.0 protobufjs-cli version: 1.0.0
How to generate static code only for necessary types from big definitions?
Current version generates static code for all types defined in protocol.proto:
pbjs --es6 --wrap=es6 --target=static-module --out=lib/protocol.js protocol.proto
I'd like to have an option like --types=Transaction,Contract to generate static code only for Transaction and Contract types.
Motivation: reduce javascript bundle size.
There's a --sparse option which will only generate the protos defined/used in protocol.proto. So if you split things up so that all your js-needed protos were referenced in some file, you could use that as the input. The --sparse option has some issues with nested types sometimes, but there's a PR here https://github.com/protobufjs/protobuf.js/pull/1528 which address them.
I found a solution, Eventually I cut myfile from 100,000 lines to 10,000. and i think it's more easy to use than --sparse.
pr here: https://github.com/protobufjs/protobuf.js/pull/1840
I found a solution, Eventually I cut myfile from 100,000 lines to 10,000. and i think it's more easy to use than --sparse.
pr here: #1840
Nice job, I have been waiting this feature for 6 months.