[feature] Enable customizing networking library reducing bundle size #113
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.
Fixes #103 .
Motivation
The core of rest-hooks clocks in at around 7kb gzip. However, there is one part - superagent - which is quite sizable. If someone decides to override their networking library it won't get tree-shaked out due to it being included in the Resource class. This results in what is essentially a doubling of this library's impact on their bundle size.
Solution
Splitting out the fetch implementation to a derived class allows those implementing their own fetch solution to not have to import the superagent fetch solution. This means with tree-shaking superagent will never even be included in the bundle.
Will have a follow blog post to talk about bundle sizes to clear things up since bundlephobia is pretty misleading and we have no desire to make the rest-hooks library worse just to rig artificial metrics that have no bearing in real life.