Skip to content

Conversation

natereprogle
Copy link

When I was looking into a specific issue relating to @webext-core/proxy-service, I noticed #102 that mentioned that, due to defineProxyService 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 and defineProxyService has been deprecated. defineServiceProxy no longer allows for the init function directly within, but instead requires it within the registerService 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:
Before Tree Shaking

And here is the size after tree-shaking:
After Tree Shaking

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

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.

1 participant