Make @webext-core/proxy-service
Tree-Shakeable
#111
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.
When I was looking into a specific issue relating to
@webext-core/proxy-service
, I noticed #102 that mentioned that, due todefineProxyService
requiring top-level calls to produce the exports, bundlers can't tree-shake it, causing the service code to be copied into anywhere it's used instead of just the background service.You stated you'd be welcome to a PR refactoring the package, so I tried my hand at this. I'm not sure if it follows your ideas for the package, but it at least follows your contributing standards. Documentation has been updated, tests have been written, and the demo package has been updated. Sorry about the bad commit messages, I was working on this pretty quickly and I've always been bad at commit messages haha.
A new method,
defineServiceProxy
, has been created anddefineProxyService
has been deprecated.defineServiceProxy
no longer allows for theinit
function directly within, but instead requires it within theregisterService
method that is returned. This method should also be awaited due to it using promises (This is the part I'm the least thrilled about, top-level awaits are not "great" but utilizing something like wxt should make this easy). You can therefore use things like dynamic imports or asynchronous initializers should they be needed.Let me know your thoughts! If this isn't the direction you're wanting to go with the package, I also completely understand. Just thought I'd try my hand at this issue 😁
Here is the size of the proxy demo before tree-shaking:

And here is the size after tree-shaking:

This resulted in a 28.4% decrease in the bundled package size just for the demo project.