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

Commit

Permalink
Stop inlining tslib helpers like __extends and __rest.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
benjamn committed Mar 5, 2019
1 parent 976b01b commit 1cf60f8
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,31 @@ function onwarn(message) {
}
}

const globals = {
'apollo-client': 'apollo.core',
'hoist-non-react-statics': 'hoistNonReactStatics',
'prop-types': 'propTypes',
'react': 'react',
'ts-invariant': 'invariant',
'tslib': 'tslib',
};

function external(id) {
return Object.prototype.hasOwnProperty.call(globals, id);
}

export default [
{
input: 'src/index.ts',
output: {
file: 'lib/react-apollo.esm.js',
format: 'esm',
sourcemap: true,
globals,
},
external,
plugins: [
node({
module: true,
only: ['tslib']
}),
node({ module: true }),
typescriptPlugin({ typescript }),
invariantPlugin(),
filesize(),
Expand All @@ -37,26 +49,32 @@ export default [
output: {
file: 'lib/react-apollo.cjs.js',
format: 'cjs',
name: 'react-apollo'
name: 'react-apollo',
globals,
},
external,
onwarn,
},
{
input: 'lib/react-apollo.esm.js',
output: {
file: 'lib/react-apollo.umd.js',
format: 'umd',
name: 'react-apollo'
name: 'react-apollo',
globals,
},
external,
onwarn,
},
{
input: 'lib/react-apollo.esm.js',
output: {
file: 'dist/bundlesize.js',
format: 'cjs',
name: 'react-apollo'
name: 'react-apollo',
globals,
},
external,
plugins: [
uglify({
mangle: {
Expand Down

0 comments on commit 1cf60f8

Please sign in to comment.