From 2f3eee73aa6c99e79c3f3432f287fde61dc118db Mon Sep 17 00:00:00 2001 From: aleclarson Date: Sat, 22 Dec 2018 14:15:17 -0500 Subject: [PATCH] Pass the maxWorkers config param correctly to Metro Taken from: https://github.com/facebook/react-native/commit/202715c95d13c6a03e43087231d14f8ebebaa6e3 Summary: @public The React Native CLI is not passing the default `maxWorkers` param to Metro, making it run in a single thread and making the development process really slow. This fixes facebook/metro#253 Reviewed By: mjesun Differential Revision: D9915500 fbshipit-source-id: d15030af582e99fe20535c07e751cfe12e444f2f --- local-cli/server/server.js | 17 +++++------------ local-cli/util/Config.js | 3 +++ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/local-cli/server/server.js b/local-cli/server/server.js index 5862af217b..8cfb3d193e 100644 --- a/local-cli/server/server.js +++ b/local-cli/server/server.js @@ -32,8 +32,8 @@ module.exports = { options: [ { command: '--port [number]', - default: process.env.RCT_METRO_PORT || 8081, parse: (val: string) => Number(val), + default: (config: ConfigT) => config.server.port, }, { command: '--host [string]', @@ -42,18 +42,14 @@ module.exports = { { command: '--projectRoot [string]', description: 'Specify the main project root', - default: (config: ConfigT) => { - return config.projectRoot; - }, + default: (config: ConfigT) => config.projectRoot, }, { command: '--watchFolders [list]', description: 'Specify any additional folders to be added to the watch list', parse: (val: string) => val.split(','), - default: (config: ConfigT) => { - return config.watchFolders; - }, + default: (config: ConfigT) => config.watchFolders, }, { command: '--assetExts [list]', @@ -81,11 +77,7 @@ module.exports = { description: 'Specify any npm packages that import dependencies with providesModule', parse: (val: string) => val.split(','), - default: (config: RNConfig) => { - return config.resolver - ? config.resolver.providesModuleNodeModules - : undefined; - }, + default: (config: ConfigT) => config.resolver.providesModuleNodeModules, }, { command: '--max-workers [number]', @@ -93,6 +85,7 @@ module.exports = { 'Specifies the maximum number of workers the worker-pool ' + 'will spawn for transforming files. This defaults to the number of the ' + 'cores available on your machine.', + default: (config: ConfigT) => config.maxWorkers, parse: (workers: string) => Number(workers), }, { diff --git a/local-cli/util/Config.js b/local-cli/util/Config.js index f663d29410..dca58c174e 100644 --- a/local-cli/util/Config.js +++ b/local-cli/util/Config.js @@ -76,6 +76,9 @@ const Config = { ], getPolyfills, }, + server: { + port: process.env.RCT_METRO_PORT || 8081, + }, transformer: { babelTransformerPath: require.resolve( 'metro/src/reactNativeTransformer.js',