From afdc9d27ce460f475a4c7e2b04efb034896423d3 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Tue, 11 Apr 2017 13:22:09 -0700 Subject: [PATCH] Tweaked legacy module inlining to remove order-of-deps constraint --- scripts/rollup/modules.js | 30 ++++++++++++++---------------- scripts/rollup/results.json | 12 ++++++------ 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/scripts/rollup/modules.js b/scripts/rollup/modules.js index b755bf0cf100a..985fe8869087a 100644 --- a/scripts/rollup/modules.js +++ b/scripts/rollup/modules.js @@ -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 @@ -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: diff --git a/scripts/rollup/results.json b/scripts/rollup/results.json index 46bbdc9378628..d676282dc3bff 100644 --- a/scripts/rollup/results.json +++ b/scripts/rollup/results.json @@ -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, @@ -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,