From 6e92599488031d9ced9ceb504fddc07f2f21b07a Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Thu, 13 Dec 2018 17:16:34 -0500 Subject: [PATCH] Import helpers like __extends from tslib. This reduces the minified size of lib/react-apollo.umd.js from 28074B to 22773B (18.9%). The minified+gzip size drops from 6930B to 6451B (6.9%). The gzip percentage is smaller because there was some repetition between the multiple declarations of the __extends function, and gzip is good at compressing long repeated substrings. --- package.json | 3 ++- rollup.config.js | 62 ++++++++++++++++++------------------------------ tsconfig.json | 1 + 3 files changed, 26 insertions(+), 40 deletions(-) diff --git a/package.json b/package.json index 04a763e569..9d35867132 100644 --- a/package.json +++ b/package.json @@ -153,6 +153,7 @@ "hoist-non-react-statics": "^3.0.0", "invariant": "^2.2.2", "lodash.isequal": "^4.5.0", - "prop-types": "^15.6.0" + "prop-types": "^15.6.0", + "tslib": "^1.9.3" } } diff --git a/rollup.config.js b/rollup.config.js index 8ab8d4b7e5..e72c5ff20b 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -11,55 +11,39 @@ function onwarn(message) { } } -export default [ - // for browser - { - input: 'lib/browser.js', +function umd(inputFile, outputFile) { + return { + input: inputFile, output: { - file: 'lib/react-apollo.browser.umd.js', + file: outputFile, format: 'umd', name: 'react-apollo', sourcemap: true, exports: 'named', }, + plugins: [ + node({ + module: true, + only: ['tslib'] + }) + ], onwarn, - }, + }; +} + +export default [ + // for browser + umd("lib/browser.js", + "lib/react-apollo.browser.umd.js"), // for server - { - input: 'lib/index.js', - output: { - file: 'lib/react-apollo.umd.js', - format: 'umd', - name: 'react-apollo', - sourcemap: false, - exports: 'named', - }, - onwarn, - }, + umd("lib/index.js", + "lib/react-apollo.umd.js"), // for test-utils - { - input: 'lib/test-utils.js', - output: { - file: 'lib/test-utils.js', - format: 'umd', - name: 'react-apollo', - sourcemap: false, - exports: 'named', - }, - onwarn, - }, + umd("lib/test-utils.js", + "lib/test-utils.js"), // for test-links - { - input: 'lib/test-links.js', - output: { - file: 'lib/test-links.js', - format: 'umd', - name: 'react-apollo', - sourcemap: false, - exports: 'named', - }, - onwarn, - }, + umd("lib/test-links.js", + "lib/test-links.js"), // for filesize { input: 'lib/react-apollo.browser.umd.js', diff --git a/tsconfig.json b/tsconfig.json index 766cef61dd..0cc499e3a8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,6 +6,7 @@ "lib": ["es2015", "dom"], "module": "es2015", "moduleResolution": "node", + "importHelpers": true, "noUnusedParameters": true, "outDir": "lib", "pretty": true,