Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): generate static files at the granularity of proto messages #1840

Merged

Conversation

vpluschen
Copy link
Contributor

@vpluschen vpluschen commented Dec 23, 2022

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.

@vpluschen vpluschen changed the title feat: add message filter for cli Feat: generate static files at the granularity of proto messages Dec 25, 2022
@alexander-fenster alexander-fenster changed the title Feat: generate static files at the granularity of proto messages feat(cli): generate static files at the granularity of proto messages Jan 24, 2023
@alexander-fenster
Copy link
Contributor

Thank you for contributing the feature with the test! I updated the jsdoc a little bit to make the linter happy. The feature seems pretty well isolated with a CLI flag, so I hope it should be pretty safe and we can fix the issues as they arise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants