protobuf.js icon indicating copy to clipboard operation
protobuf.js copied to clipboard

cli: how to generate static code only for necessary types?

Open mahnunchik opened this issue 3 years ago • 1 comments

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.

mahnunchik avatar Jul 28 '22 13:07 mahnunchik

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.

imirkin avatar Aug 02 '22 03:08 imirkin

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

vpluschen avatar Dec 25 '22 13:12 vpluschen

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.

mescoalex avatar Dec 27 '22 05:12 mescoalex