Skip to content

Commit

Permalink
Tweaked legacy module inlining to remove order-of-deps constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn committed Apr 11, 2017
1 parent 83bcb29 commit afdc9d2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
30 changes: 14 additions & 16 deletions scripts/rollup/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,13 @@ const devOnlyFilesToStubOut = [
"'ReactTestUtils'",
];

// Ordering of these imports is important;
// The default import must follow deep imports or Rollup breaks.
// eg if 'prop-types' comes before 'prop-types/checkPropTypes',
// Then Rollup might try to requite 'prop-types/index.js/checkPropTypes.js'
const legacyModules = {
'create-react-class/factory': 'create-react-class/factory.js',
'create-react-class': 'create-react-class/index.js',
'prop-types/checkPropTypes': 'prop-types/checkPropTypes.js',
'prop-types/factory': 'prop-types/factory.js',
'prop-types': 'prop-types/index.js',
};
const legacyModules = [
'create-react-class',
'create-react-class/factory',
'prop-types',
'prop-types/checkPropTypes',
'prop-types/factory',
];

// this function builds up a very niave Haste-like moduleMap
// that works to create up an alias map for modules to link
Expand Down Expand Up @@ -247,11 +243,13 @@ function replaceLegacyModuleAliases(bundleType) {
case UMD_DEV:
case UMD_PROD:
const modulesAlias = {};
for (let legacyModule in legacyModules) {
modulesAlias[legacyModule] = resolve(
`./node_modules/${legacyModules[legacyModule]}`
);
}
legacyModules.forEach(legacyModule => {
const modulePath = legacyModule.includes('/')
? legacyModule
: `${legacyModule}/index`;
const resolvedPath = resolve(`./node_modules/${modulePath}`);
modulesAlias[`'${legacyModule}'`] = `'${resolvedPath}'`;
});
return modulesAlias;
case NODE_DEV:
case NODE_PROD:
Expand Down
12 changes: 6 additions & 6 deletions scripts/rollup/results.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"branch": "prop-types",
"bundleSizes": {
"react.development.js (UMD_DEV)": {
"size": 121272,
"gzip": 30505
"size": 121474,
"gzip": 30524
},
"react.production.min.js (UMD_PROD)": {
"size": 15685,
Expand Down Expand Up @@ -34,16 +34,16 @@
"gzip": 28990
},
"react.development.js (NODE_DEV)": {
"size": 69913,
"gzip": 17542
"size": 70286,
"gzip": 17600
},
"react.production.min.js (NODE_PROD)": {
"size": 9226,
"gzip": 3626
},
"React-dev.js (FB_DEV)": {
"size": 71770,
"gzip": 18179
"size": 72143,
"gzip": 18236
},
"React-prod.js (FB_PROD)": {
"size": 36643,
Expand Down

0 comments on commit afdc9d2

Please sign in to comment.