Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Import tslib helpers from shared package rather than inlining. #959

Merged
merged 5 commits into from
Feb 26, 2019

Conversation

benjamn
Copy link
Member

@benjamn benjamn commented Feb 26, 2019

Most Apollo applications use at least three link packages: apollo-link, apollo-link-http-common, and apollo-link-http.

These packages import helpers like __extends, __assign, and __rest from the tslib package.

If we inline these helpers in each package, we can control how much of the tslib package gets bundled (only what we use), but the helpers will be duplicated unnecessarily.

By importing the helpers from tslib as an external package, we can share one copy of the tslib package among all Apollo packages, and bundlers that understand ECMAScript import syntax can still prune the contents of the tslib package to include only the helpers that are used (throughout the whole application).

@benjamn benjamn self-assigned this Feb 26, 2019
@codecov-io

This comment has been minimized.

Copy link
Contributor

@JoviDeCroock JoviDeCroock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a good idea, can’t really figure a scenario where these would be used outside of one that does not inline. We might have to double check if the helpers are all covered.

I have time to do so tonight after work.

Build seems to fail due to an out of memory

@benjamn benjamn force-pushed the import-tslib-rather-than-inlining branch from 07da19e to a79b91f Compare February 26, 2019 15:29
@benjamn
Copy link
Member Author

benjamn commented Feb 26, 2019

Thanks for the review @JoviDeCroock!

@benjamn benjamn merged commit 52d14ad into master Feb 26, 2019
@benjamn benjamn deleted the import-tslib-rather-than-inlining branch February 26, 2019 16:03
benjamn added a commit that referenced this pull request Mar 4, 2019
One of the changes in #959 that may have contributed to memory usage was
moving minification into the Rollup build pipeline. This commit moves it
back out into its own job, which is only run as part of filesize.
benjamn added a commit to apollographql/react-apollo that referenced this pull request Mar 5, 2019
Similar in spirit to apollographql/apollo-link#959

This inlining was first introduced in PR #2661 with the following commit:
de2b5fc

At the time, inlining made sense because TypeScript was injecting copies
of the __extends, __rest, etc. helpers into every module that used them.
Depending on the tslib package seemed undesirable because the available
bundle size measurement tools (e.g. bundlephobia.com) mistakenly counted
the entire tslib package against react-apollo, without acknowledging the
possibility of sharing that package between multiple Apollo packages. It
seemed safer to inline only the helpers we needed at the top of
lib/react-apollo.esm.js.

Now that we have a more holistic way to measure bundle sizes (#2839), and
react-apollo works better with tree-shaking tools (#2659, #2661, #2677),
we know that overall application bundle sizes benefit from sharing a
single copy of the tslib helper package, even if no tree-shaking is
happening. Of course, with tree-shaking, that one copy of the tslib
package can be shrunk to contain just the helpers that are actually used.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants