-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c7a1f24
commit ba3b836
Showing
10 changed files
with
179 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* 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. | ||
* | ||
* | ||
* @format | ||
* @oncall react_native | ||
*/ | ||
|
||
import type { ConfigT } from "metro-config"; | ||
export { mergeConfig } from "metro-config"; | ||
/** | ||
* Get the base Metro configuration for a React Native project. | ||
*/ | ||
export declare function getDefaultConfig(projectRoot: string): ConfigT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
"use strict"; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true, | ||
}); | ||
exports.getDefaultConfig = getDefaultConfig; | ||
Object.defineProperty(exports, "mergeConfig", { | ||
enumerable: true, | ||
get: function () { | ||
return _metroConfig.mergeConfig; | ||
}, | ||
}); | ||
var _metroConfig = require("metro-config"); | ||
/** | ||
* 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. | ||
* | ||
* | ||
* @format | ||
* @oncall react_native | ||
*/ | ||
|
||
const INTERNAL_CALLSITES_REGEX = new RegExp( | ||
[ | ||
"/Libraries/BatchedBridge/MessageQueue\\.js$", | ||
"/Libraries/Core/.+\\.js$", | ||
"/Libraries/LogBox/.+\\.js$", | ||
"/Libraries/Network/.+\\.js$", | ||
"/Libraries/Pressability/.+\\.js$", | ||
"/Libraries/Renderer/implementations/.+\\.js$", | ||
"/Libraries/Utilities/.+\\.js$", | ||
"/Libraries/vendor/.+\\.js$", | ||
"/Libraries/WebSocket/.+\\.js$", | ||
"/Libraries/YellowBox/.+\\.js$", | ||
"/metro-runtime/.+\\.js$", | ||
"/node_modules/@babel/runtime/.+\\.js$", | ||
"/node_modules/@react-native/js-polyfills/.+\\.js$", | ||
"/node_modules/event-target-shim/.+\\.js$", | ||
"/node_modules/invariant/.+\\.js$", | ||
"/node_modules/react-devtools-core/.+\\.js$", | ||
"/node_modules/react-native/index.js$", | ||
"/node_modules/react-refresh/.+\\.js$", | ||
"/node_modules/scheduler/.+\\.js$", | ||
"^\\[native code\\]$", | ||
] | ||
// Make patterns work with both Windows and POSIX paths. | ||
.map((pathPattern) => pathPattern.replaceAll("/", "[/\\\\]")) | ||
.join("|") | ||
); | ||
/** | ||
* Get the base Metro configuration for a React Native project. | ||
*/ | ||
function getDefaultConfig(projectRoot) { | ||
const config = { | ||
resolver: { | ||
resolverMainFields: ["react-native", "browser", "main"], | ||
platforms: ["android", "ios"], | ||
unstable_conditionNames: ["require", "import", "react-native"], | ||
}, | ||
serializer: { | ||
// Note: This option is overridden in cli-plugin-metro (getOverrideConfig) | ||
getModulesRunBeforeMainModule: () => [ | ||
require.resolve("react-native/Libraries/Core/InitializeCore"), | ||
], | ||
getPolyfills: () => require("@react-native/js-polyfills")(), | ||
isThirdPartyModule({ path: modulePath }) { | ||
return ( | ||
INTERNAL_CALLSITES_REGEX.test(modulePath) || | ||
/(?:^|[/\\])node_modules[/\\]/.test(modulePath) | ||
); | ||
}, | ||
}, | ||
server: { | ||
port: Number(process.env.RCT_METRO_PORT) || 8081, | ||
}, | ||
symbolicator: { | ||
customizeFrame: (frame) => { | ||
const collapse = Boolean( | ||
frame.file != null && 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( | ||
"@react-native/metro-babel-transformer" | ||
), | ||
getTransformOptions: async () => ({ | ||
transform: { | ||
experimentalImportSupport: false, | ||
inlineRequires: true, | ||
}, | ||
}), | ||
}, | ||
watchFolders: [], | ||
}; | ||
|
||
// Set global hook so that the CLI can detect when this config has been loaded | ||
global.__REACT_NATIVE_METRO_CONFIG_LOADED = true; | ||
return (0, _metroConfig.mergeConfig)( | ||
_metroConfig.getDefaultConfig.getDefaultValues(projectRoot), | ||
config | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* 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 strict-local | ||
* @format | ||
* @oncall react_native | ||
*/ | ||
|
||
import type { ConfigT } from "metro-config"; | ||
|
||
export { mergeConfig } from "metro-config"; | ||
|
||
/** | ||
* Get the base Metro configuration for a React Native project. | ||
*/ | ||
declare export function getDefaultConfig(projectRoot: string): ConfigT; |