@samitouri / QOS-React-2 / commits / f74981beee

Share Object.assign polyfill between UMD builds (#10671)

Dan Abramov committed Sep 11, 2017 at 19:22 UTC f74981beeeead5c0ac44a4dc733707457ab80e68
4 files changed +37 -27
scripts/rollup/modules.js
+7 -3
@@ -87,7 +87,7 @@ function createModuleMap(paths, extractErrors, bundleType) {
87 return moduleMap;
88 }
89
90 -function getNodeModules(bundleType) {
90 +function getNodeModules(bundleType, isRenderer) {
91 // rather than adding the rollup node resolve plugin,
92 // we can instead deal with the only node module that is used
93 // for UMD bundles - object-assign
@@ -95,7 +95,11 @@ function getNodeModules(bundleType) {
95 case UMD_DEV:
96 case UMD_PROD:
97 return {
98 - 'object-assign': resolve('./node_modules/object-assign/index.js'),
98 + // Bundle object-assign once in the isomorphic React, and then use
99 + // that from the renderer UMD. Avoids bundling it in both UMDs.
100 + 'object-assign': isRenderer
101 + ? resolve('./scripts/rollup/shims/rollup/assign.js')
102 + : resolve('./node_modules/object-assign/index.js'),
103 // include the ART package modules directly by aliasing them from node_modules
104 'art/modes/current': resolve('./node_modules/art/modes/current.js'),
105 'art/modes/fast-noSideEffects': resolve(
@@ -286,7 +290,7 @@ function getAliases(paths, bundleType, isRenderer, extractErrors) {
290 bundleType
291 ),
292 getInternalModules(),
289 - getNodeModules(bundleType),
293 + getNodeModules(bundleType, isRenderer),
294 getFbjsModuleAliases(bundleType)
295 );
296 }
scripts/rollup/results.json
+24 -24
@@ -1,36 +1,36 @@
1 {
2 "bundleSizes": {
3 "react.development.js (UMD_DEV)": {
4 - "size": 66238,
5 - "gzip": 16739
4 + "size": 66336,
5 + "gzip": 16788
6 },
7 "react.production.min.js (UMD_PROD)": {
8 - "size": 6707,
9 - "gzip": 2801
8 + "size": 6716,
9 + "gzip": 2804
10 },
11 "react.development.js (NODE_DEV)": {
12 - "size": 56692,
13 - "gzip": 14483
12 + "size": 56799,
13 + "gzip": 14530
14 },
15 "react.production.min.js (NODE_PROD)": {
16 - "size": 5730,
17 - "gzip": 2416
16 + "size": 5739,
17 + "gzip": 2421
18 },
19 "React-dev.js (FB_DEV)": {
20 - "size": 53533,
21 - "gzip": 13666
20 + "size": 53683,
21 + "gzip": 13731
22 },
23 "React-prod.js (FB_PROD)": {
24 - "size": 25034,
25 - "gzip": 6707
24 + "size": 25188,
25 + "gzip": 6767
26 },
27 "react-dom.development.js (UMD_DEV)": {
28 - "size": 649654,
29 - "gzip": 149173
28 + "size": 647720,
29 + "gzip": 148505
30 },
31 "react-dom.production.min.js (UMD_PROD)": {
32 - "size": 103686,
33 - "gzip": 32364
32 + "size": 102839,
33 + "gzip": 32049
34 },
35 "react-dom.development.js (NODE_DEV)": {
36 "size": 608523,
@@ -81,12 +81,12 @@
81 "gzip": 15742
82 },
83 "react-dom-server.browser.development.js (UMD_DEV)": {
84 - "size": 136901,
85 - "gzip": 34895
84 + "size": 134937,
85 + "gzip": 34221
86 },
87 "react-dom-server.browser.production.min.js (UMD_PROD)": {
88 - "size": 15917,
89 - "gzip": 6199
88 + "size": 15077,
89 + "gzip": 5914
90 },
91 "react-dom-server.browser.development.js (NODE_DEV)": {
92 "size": 105249,
@@ -113,12 +113,12 @@
113 "gzip": 6238
114 },
115 "react-art.development.js (UMD_DEV)": {
116 - "size": 372313,
117 - "gzip": 82691
116 + "size": 370239,
117 + "gzip": 81901
118 },
119 "react-art.production.min.js (UMD_PROD)": {
120 - "size": 83447,
121 - "gzip": 25837
120 + "size": 82583,
121 + "gzip": 25472
122 },
123 "react-art.development.js (NODE_DEV)": {
124 "size": 293850,
scripts/rollup/shims/rollup/assign.js new
+4
@@ -0,0 +1,4 @@
1 +var ReactInternals = require('react')
2 + .__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
3 +
4 +module.exports = ReactInternals.assign;
src/isomorphic/ReactEntry.js
+2
@@ -52,6 +52,8 @@ var React = {
52
53 __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: {
54 ReactCurrentOwner: require('ReactCurrentOwner'),
55 + // Used by renderers to avoid bundling object-assign twice in UMD bundles:
56 + assign: require('object-assign'),
57 },
58 };
59