Skip to content

Commit f74981b

Browse files
authored
Share Object.assign polyfill between UMD builds (#10671)
1 parent 61282d3 commit f74981b

File tree

4 files changed

+37
-27
lines changed

4 files changed

+37
-27
lines changed

scripts/rollup/modules.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,19 @@ function createModuleMap(paths, extractErrors, bundleType) {
8787
return moduleMap;
8888
}
8989

90-
function getNodeModules(bundleType) {
90+
function getNodeModules(bundleType, isRenderer) {
9191
// rather than adding the rollup node resolve plugin,
9292
// we can instead deal with the only node module that is used
9393
// for UMD bundles - object-assign
9494
switch (bundleType) {
9595
case UMD_DEV:
9696
case UMD_PROD:
9797
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'),
99103
// include the ART package modules directly by aliasing them from node_modules
100104
'art/modes/current': resolve('./node_modules/art/modes/current.js'),
101105
'art/modes/fast-noSideEffects': resolve(
@@ -286,7 +290,7 @@ function getAliases(paths, bundleType, isRenderer, extractErrors) {
286290
bundleType
287291
),
288292
getInternalModules(),
289-
getNodeModules(bundleType),
293+
getNodeModules(bundleType, isRenderer),
290294
getFbjsModuleAliases(bundleType)
291295
);
292296
}

scripts/rollup/results.json

+24-24
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
{
22
"bundleSizes": {
33
"react.development.js (UMD_DEV)": {
4-
"size": 66238,
5-
"gzip": 16739
4+
"size": 66336,
5+
"gzip": 16788
66
},
77
"react.production.min.js (UMD_PROD)": {
8-
"size": 6707,
9-
"gzip": 2801
8+
"size": 6716,
9+
"gzip": 2804
1010
},
1111
"react.development.js (NODE_DEV)": {
12-
"size": 56692,
13-
"gzip": 14483
12+
"size": 56799,
13+
"gzip": 14530
1414
},
1515
"react.production.min.js (NODE_PROD)": {
16-
"size": 5730,
17-
"gzip": 2416
16+
"size": 5739,
17+
"gzip": 2421
1818
},
1919
"React-dev.js (FB_DEV)": {
20-
"size": 53533,
21-
"gzip": 13666
20+
"size": 53683,
21+
"gzip": 13731
2222
},
2323
"React-prod.js (FB_PROD)": {
24-
"size": 25034,
25-
"gzip": 6707
24+
"size": 25188,
25+
"gzip": 6767
2626
},
2727
"react-dom.development.js (UMD_DEV)": {
28-
"size": 649654,
29-
"gzip": 149173
28+
"size": 647720,
29+
"gzip": 148505
3030
},
3131
"react-dom.production.min.js (UMD_PROD)": {
32-
"size": 103686,
33-
"gzip": 32364
32+
"size": 102839,
33+
"gzip": 32049
3434
},
3535
"react-dom.development.js (NODE_DEV)": {
3636
"size": 608523,
@@ -81,12 +81,12 @@
8181
"gzip": 15742
8282
},
8383
"react-dom-server.browser.development.js (UMD_DEV)": {
84-
"size": 136901,
85-
"gzip": 34895
84+
"size": 134937,
85+
"gzip": 34221
8686
},
8787
"react-dom-server.browser.production.min.js (UMD_PROD)": {
88-
"size": 15917,
89-
"gzip": 6199
88+
"size": 15077,
89+
"gzip": 5914
9090
},
9191
"react-dom-server.browser.development.js (NODE_DEV)": {
9292
"size": 105249,
@@ -113,12 +113,12 @@
113113
"gzip": 6238
114114
},
115115
"react-art.development.js (UMD_DEV)": {
116-
"size": 372313,
117-
"gzip": 82691
116+
"size": 370239,
117+
"gzip": 81901
118118
},
119119
"react-art.production.min.js (UMD_PROD)": {
120-
"size": 83447,
121-
"gzip": 25837
120+
"size": 82583,
121+
"gzip": 25472
122122
},
123123
"react-art.development.js (NODE_DEV)": {
124124
"size": 293850,

scripts/rollup/shims/rollup/assign.js

+4
Original file line numberDiff line numberDiff line change
@@ -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
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ var React = {
5252

5353
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: {
5454
ReactCurrentOwner: require('ReactCurrentOwner'),
55+
// Used by renderers to avoid bundling object-assign twice in UMD bundles:
56+
assign: require('object-assign'),
5557
},
5658
};
5759

0 commit comments

Comments
 (0)