-
Notifications
You must be signed in to change notification settings - Fork 344
Shrink apollo-link[-http-common] packages. #969
Conversation
Since every application that uses any links uses both the apollo-link package and the apollo-client package, and apollo-client already imports getOperationName from apollo-utilities, we can avoid duplicating that code in apollo-link. This only saves 37 bytes after gzip (84 bytes minified), but that's not nothing.
This saves 93 bytes after gzip (161 bytes minified).
Codecov Report
@@ Coverage Diff @@
## master #969 +/- ##
=======================================
Coverage 95.23% 95.23%
=======================================
Files 22 22
Lines 1028 1028
Branches 109 107 -2
=======================================
Hits 979 979
Misses 44 44
Partials 5 5
Continue to review full report at Codecov.
|
@@ -70,6 +77,9 @@ export default name => [ | |||
}, | |||
}, | |||
}), | |||
invariantPlugin({ | |||
errorCodes: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See apollographql/apollo-client#4521 for more explanation of what this option does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's actually a really nice solution for having some errors in production. That rollup plugin is really smart
This reduces the minified+gzip byte size of the package from 1227 to 1045, a 15% improvement.
I'll probably try to find some low-hanging in link-packages today, so that might further reduce the bundlesize. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks really promising, I think the apollo repositories are really on the right track when it comes to bundle size. Good job @benjamn
As apollographql/react-apollo#2839 has helped to demonstrate, sharing dependencies between Apollo packages is a great way to improve overall bundle size, especially if the shared dependencies can be tree-shaken to remove unused exports.
This PR includes two changes to the
apollo-link
package, which is used directly or indirectly by any application that uses any of the packages in this repository:Import
getOperationName
fromapollo-utilities
, since that implementation is almost certainly already imported byapollo-client
.Use
invariant.warn
andInvariantError
instead ofconsole.warn
andError
, since those utilities allow long error strings to be stripped in production, thanks to https://github.com/apollographql/invariant-packages.Together, these tweaks reduce the minified+gzip size of the
apollo-link
package from 1271 bytes to 1123 bytes, a 12% improvement.