feat(cli): generate static files at the granularity of proto messages #1840
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I encountered a problem in the project I was working on: Due to the large size of my project and the complexity of the proto, the resulting js static code file was very large, nearly 100,000 lines before uncompression, about 5mb, and nearly 1mb even after compression , which causes my pages to load slower.
Later I found out the cause of the problem: my page only uses a few messages, but I still need to compile the entire file and all the messages, enums, etc. of all dependent files, and there is a huge waste here.
Finally, I found a solution: by adding a filter parameter to the cli, to filter those structures that we don't need at all, so that our files are greatly reduced, which will be very useful in a huge project. Eventually I cut it from 100,000 lines to 10,000.
example:
pbjs --target=static-module --filter=/home/filter.json --out=appsvr-source.js proto/appsvr.proto
/home/filter.json:
{ "messageName": ["mypackage.message1", "message2"]}
then, only mypackage.message1 and message2 and their dependencies will gen in code.
Hope this solution can help others.