Files
JKVideo/metro.config.js
Action 6f7c99906b fix(web): 补全缺失的 web shims 并修复渲染崩溃问题
- 新增 sentry-react-native、react-native-video、react-native-static-server、expo-network、expo-intent-launcher、expo-clipboard、expo-file-system 的 web shim
- 重写 react-native-pager-view shim,通过 useImperativeHandle 暴露 setPage 方法
- 修复 sentry-react-native shim 缺少 ErrorBoundary 导致的渲染崩溃
- 在 _layout.tsx 中加载 Ionicons 字体,修复 web 端字体 404
- 更新 metro.config.js 中 sentry shim 路径为 .tsx
2026-03-24 21:21:15 +08:00

37 lines
1.5 KiB
JavaScript

const path = require('path');
const { getSentryExpoConfig } = require("@sentry/react-native/metro");
const config = getSentryExpoConfig(__dirname);
// Ensure shims directory is watched by Metro
config.watchFolders = [...(config.watchFolders ?? []), path.resolve(__dirname, 'shims')];
const originalResolveRequest = config.resolver.resolveRequest;
const WEB_SHIMS = {
'react-native-pager-view': 'shims/react-native-pager-view.web.tsx',
'@sentry/react-native': 'shims/sentry-react-native.web.tsx',
'@dr.pogodin/react-native-static-server': 'shims/react-native-static-server.web.ts',
'expo-network': 'shims/expo-network.web.ts',
'expo-intent-launcher': 'shims/expo-intent-launcher.web.ts',
'react-native-video': 'shims/react-native-video.web.tsx',
'expo-file-system': 'shims/expo-file-system.web.ts',
'expo-file-system/legacy': 'shims/expo-file-system.web.ts',
'expo-clipboard': 'shims/expo-clipboard.web.ts',
};
config.resolver.resolveRequest = (context, moduleName, platform) => {
if (platform === 'web' && WEB_SHIMS[moduleName]) {
return {
filePath: path.resolve(__dirname, WEB_SHIMS[moduleName]),
type: 'sourceFile',
};
}
if (originalResolveRequest) {
return originalResolveRequest(context, moduleName, platform);
}
return context.resolveRequest(context, moduleName, platform);
};
module.exports = config;