mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/36777 Changelog: [Internal] Remove internal merge of `getDefaultConfig` (Metro base defaults) from `react-native/metro-config`. This is unnecessary given the config loading setup of RN CLI and Expo CLI, which use (or replicate) Metro's [`loadConfig`](https://github.com/facebook/metro/blob/1e47cb5b3cc289530fb18e402891f9d2816611dd/packages/metro-config/src/loadConfig.js#L182-L190) function — which will itself apply defaults appropriately. This relates to a previously-breaking behaviour documented in the test plan of https://github.com/react-native-community/cli/pull/1896 (independently fixed and no longer load-bearing) (**read: no need to cherry pick this change**). https://pxl.cl/2B8NS While this has no effect under the fixed RN CLI setup, this is a worthwhile simplification to this package that better-aligns with current Metro tooling expectations. ## Notes - `getDefaultConfig` no longer returns `ConfigT` (full config), and instead returns `MetroConfig` (partial config). This is non-breaking with the expected API of a given `metro.config.js` file. Reviewed By: cipolleschi Differential Revision: D44630645 fbshipit-source-id: 472c3967449dfb99f845a82d9e9c49efc343021c
82 lines
2.3 KiB
JavaScript
82 lines
2.3 KiB
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @flow
|
|
* @noformat
|
|
*/
|
|
|
|
/*:: import type {MetroConfig} from 'metro-config'; */
|
|
|
|
const {mergeConfig} = require('metro-config');
|
|
|
|
const INTERNAL_CALLSITES_REGEX = new RegExp(
|
|
[
|
|
'/Libraries/Renderer/implementations/.+\\.js$',
|
|
'/Libraries/BatchedBridge/MessageQueue\\.js$',
|
|
'/Libraries/YellowBox/.+\\.js$',
|
|
'/Libraries/LogBox/.+\\.js$',
|
|
'/Libraries/Core/Timers/.+\\.js$',
|
|
'/Libraries/WebSocket/.+\\.js$',
|
|
'/Libraries/vendor/.+\\.js$',
|
|
'/node_modules/react-devtools-core/.+\\.js$',
|
|
'/node_modules/react-refresh/.+\\.js$',
|
|
'/node_modules/scheduler/.+\\.js$',
|
|
'/node_modules/event-target-shim/.+\\.js$',
|
|
'/node_modules/invariant/.+\\.js$',
|
|
'/node_modules/react-native/index.js$',
|
|
'/metro-runtime/.+\\.js$',
|
|
'^\\[native code\\]$',
|
|
].join('|'),
|
|
);
|
|
|
|
/**
|
|
* Get the base Metro configuration for a React Native project.
|
|
*/
|
|
function getDefaultConfig(
|
|
projectRoot /*: string */
|
|
) /*: MetroConfig */ {
|
|
return {
|
|
resolver: {
|
|
resolverMainFields: ['react-native', 'browser', 'main'],
|
|
platforms: ['android', 'ios'],
|
|
unstable_conditionNames: ['require', 'import', 'react-native'],
|
|
},
|
|
serializer: {
|
|
getPolyfills: () => require('@react-native/js-polyfills')(),
|
|
},
|
|
server: {
|
|
port: Number(process.env.RCT_METRO_PORT) || 8081,
|
|
},
|
|
symbolicator: {
|
|
customizeFrame: (frame /*: $ReadOnly<{file: ?string, ...}>*/) => {
|
|
const collapse = Boolean(
|
|
frame.file && INTERNAL_CALLSITES_REGEX.test(frame.file),
|
|
);
|
|
return {collapse};
|
|
},
|
|
},
|
|
transformer: {
|
|
allowOptionalDependencies: true,
|
|
assetRegistryPath: 'react-native/Libraries/Image/AssetRegistry',
|
|
asyncRequireModulePath: require.resolve(
|
|
'metro-runtime/src/modules/asyncRequire',
|
|
),
|
|
babelTransformerPath: require.resolve(
|
|
'metro-react-native-babel-transformer',
|
|
),
|
|
getTransformOptions: async () => ({
|
|
transform: {
|
|
experimentalImportSupport: false,
|
|
inlineRequires: true,
|
|
},
|
|
}),
|
|
},
|
|
watchFolders: [],
|
|
};
|
|
}
|
|
|
|
module.exports = {getDefaultConfig, mergeConfig};
|