From 7e5af6263981819655d5725964182516ae847374 Mon Sep 17 00:00:00 2001 From: Alex Hunt Date: Wed, 28 Jun 2023 03:48:43 -0700 Subject: [PATCH] Restore base config merge in metro-config (#38092) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/38092 Reverts https://github.com/facebook/react-native/pull/36777. This is motivated by reducing user friction when the widespread assumption is for `react-native/metro-config` to export a complete Metro config, as with Expo/rnx-kit, and like previously understood uses of `metro-config`. See https://github.com/facebook/metro/issues/1010#issuecomment-1609215165 for further notes. Fixes: - https://github.com/facebook/metro/issues/1010 - https://github.com/facebook/react-native/issues/38069 - https://github.com/kristerkari/react-native-svg-transformer/issues/276 Note that we do not intend for `react-native/metro-config` to directly export `assetExts` etc — these can be accessed on the `resolver` property from the full config object. Changelog: [General][Changed] `react-native/metro-config` now includes all base config values from `metro-config` Reviewed By: robhogan Differential Revision: D47055973 fbshipit-source-id: eedc4698e651645ada46a013d3945a16965bff22 --- packages/metro-config/index.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/metro-config/index.js b/packages/metro-config/index.js index e88df579040627..c43b46a34b8cf9 100644 --- a/packages/metro-config/index.js +++ b/packages/metro-config/index.js @@ -8,9 +8,9 @@ * @noformat */ -/*:: import type {MetroConfig} from 'metro-config'; */ +/*:: import type {ConfigT} from 'metro-config'; */ -const {mergeConfig} = require('metro-config'); +const {getDefaultConfig: getBaseConfig, mergeConfig} = require('metro-config'); const INTERNAL_CALLSITES_REGEX = new RegExp( [ @@ -37,8 +37,8 @@ const INTERNAL_CALLSITES_REGEX = new RegExp( */ function getDefaultConfig( projectRoot /*: string */ -) /*: MetroConfig */ { - return { +) /*: ConfigT */ { + const config = { resolver: { resolverMainFields: ['react-native', 'browser', 'main'], platforms: ['android', 'ios'], @@ -76,6 +76,11 @@ function getDefaultConfig( }, watchFolders: [], }; + + return mergeConfig( + getBaseConfig.getDefaultValues(projectRoot), + config, + ); } module.exports = {getDefaultConfig, mergeConfig};