metro.config.ts
Rama main · réplica de lectura del repositorio original.
// Learn more https://docs.expo.io/guides/customizing-metro
import {withNanoIcons} from 'react-native-nano-icons/metro'
import {getBundleModeMetroConfig} from 'react-native-worklets/bundleMode/index.js'
import {type CustomResolver} from '@expo/metro/metro-resolver'
import {getDefaultConfig} from '@expo/metro-config'
import {getSentryExpoConfig} from '@sentry/react-native/metro.js'
let config = getSentryExpoConfig(import.meta.dirname, {
// TODO: confirm this doesn't break anything when we switch to metro web
includeWebReplay: false,
includeWebFeedback: false,
annotateReactComponents: {
textComponentNames: ['Text', 'ButtonText'],
},
getDefaultConfig: (projectRoot, options) => {
const config = getDefaultConfig(projectRoot, options)
if (typeof process.env.RN_SRC_EXT === 'string') {
// inject `.e2e.ts` and `.e2e.tsx` into the sourceExts when running tests)
config.resolver.sourceExts.unshift(...process.env.RN_SRC_EXT.split(','))
}
config.resolver.assetExts = [...config.resolver.assetExts, 'woff2']
if (config.resolver.resolveRequest) {
throw Error('Update this override because it is conflicting now.')
}
if (process.env.BSKY_PROFILE) {
// @ts-expect-error readonly property
config.cacheVersion += ':PROFILE'
}
const resolver: CustomResolver = (context, moduleName, platform) => {
if (
platform === 'web' &&
/^react-native-gesture-handler(\/|$)/.test(moduleName)
) {
throw new Error(
`react-native-gesture-handler must not be imported on web (requested from ${context.originModulePath})`,
)
}
/*
* react-native-webview has no web implementation (its fallback renders
* "does not support this platform"), so swap in react-native-web-webview
* to keep external media embeds working. Mirrors the old webpack alias.
*/
if (platform === 'web' && moduleName === 'react-native-webview') {
return context.resolveRequest(
context,
'react-native-web-webview',
platform,
)
}
if (
process.env.BSKY_PROFILE &&
moduleName.endsWith('ReactNativeRenderer-prod')
) {
return context.resolveRequest(
context,
moduleName.replace('-prod', '-profiling'),
platform,
)
}
return context.resolveRequest(context, moduleName, platform)
}
// @ts-expect-error readonly property
config.resolver.resolveRequest = resolver
config.transformer.getTransformOptions = () =>
Promise.resolve({
transform: {
experimentalImportSupport: true,
inlineRequires: true as false, // ??? typescript why?
},
})
return config as unknown as Record<string, unknown>
},
})
config = getBundleModeMetroConfig(config)
/*
* The icon fonts are baked into the native binary, so a dev client built from
* an older commit lacks the glyphs the current glyphmaps point at, and those
* icons render blank. In development this serves the current fonts from the
* dev server, and nano-icons registers them at runtime when the binary's font
* doesn't match. When an SVG changes, it also rebuilds that font and its
* glyphmap in `assets/nano-icons/`, like `pnpm icons:generate` would. It does
* nothing in production, where the fonts must ship in the binary.
*/
config = withNanoIcons(config)
export default config