Skip to content

Commit

Permalink
Share Object.assign polyfill between UMD builds
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Sep 11, 2017
1 parent 6552519 commit 3df1ffe
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
10 changes: 7 additions & 3 deletions scripts/rollup/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,19 @@ function createModuleMap(paths, extractErrors, bundleType) {
return moduleMap;
}

function getNodeModules(bundleType) {
function getNodeModules(bundleType, isRenderer) {
// rather than adding the rollup node resolve plugin,
// we can instead deal with the only node module that is used
// for UMD bundles - object-assign
switch (bundleType) {
case UMD_DEV:
case UMD_PROD:
return {
'object-assign': resolve('./node_modules/object-assign/index.js'),
// Bundle object-assign once in the isomorphic React, and then use
// that from the renderer UMD. Avoids bundling it in both UMDs.
'object-assign': isRenderer
? resolve('./scripts/rollup/shims/rollup/assign.js')
: resolve('./node_modules/object-assign/index.js'),
// include the ART package modules directly by aliasing them from node_modules
'art/modes/current': resolve('./node_modules/art/modes/current.js'),
'art/modes/fast-noSideEffects': resolve(
Expand Down Expand Up @@ -286,7 +290,7 @@ function getAliases(paths, bundleType, isRenderer, extractErrors) {
bundleType
),
getInternalModules(),
getNodeModules(bundleType),
getNodeModules(bundleType, isRenderer),
getFbjsModuleAliases(bundleType)
);
}
Expand Down
24 changes: 12 additions & 12 deletions scripts/rollup/results.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"bundleSizes": {
"react.development.js (UMD_DEV)": {
"size": 66238,
"gzip": 16739
"size": 66336,
"gzip": 16788
},
"react.production.min.js (UMD_PROD)": {
"size": 6707,
"gzip": 2801
"size": 6716,
"gzip": 2804
},
"react.development.js (NODE_DEV)": {
"size": 56692,
Expand All @@ -25,12 +25,12 @@
"gzip": 6707
},
"react-dom.development.js (UMD_DEV)": {
"size": 649654,
"gzip": 149173
"size": 647720,
"gzip": 148505
},
"react-dom.production.min.js (UMD_PROD)": {
"size": 103686,
"gzip": 32364
"size": 102839,
"gzip": 32049
},
"react-dom.development.js (NODE_DEV)": {
"size": 608523,
Expand Down Expand Up @@ -81,12 +81,12 @@
"gzip": 15742
},
"react-dom-server.browser.development.js (UMD_DEV)": {
"size": 136901,
"gzip": 34895
"size": 134937,
"gzip": 34221
},
"react-dom-server.browser.production.min.js (UMD_PROD)": {
"size": 15917,
"gzip": 6199
"size": 15077,
"gzip": 5914
},
"react-dom-server.browser.development.js (NODE_DEV)": {
"size": 105249,
Expand Down
4 changes: 4 additions & 0 deletions scripts/rollup/shims/rollup/assign.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var ReactInternals = require('react')
.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;

module.exports = ReactInternals.assign;
2 changes: 2 additions & 0 deletions src/isomorphic/ReactEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ var React = {

__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: {
ReactCurrentOwner: require('ReactCurrentOwner'),
// Used by renderers to avoid bundling object-assign twice in UMD bundles:
assign: require('object-assign'),
},
};

Expand Down

0 comments on commit 3df1ffe

Please sign in to comment.