react-phone-apps/apps/property-survey/metro.config.js
lanrtop f8fdb9d34e chore: 修复 pnpm monorepo 在 Windows 上 Android release 构建失败的问题
- 降级与 SDK 52 不兼容的包版本:expo-secure-store(55→13)、expo-linking 锁定 ~7.0.5、expo-image-manipulator 锁定 ~13.0.0
- 根 package.json 添加 pnpm overrides 锁定 expo-constants ~17.0.8,防止子依赖安装 SDK53+ 版本
- 修复 metro.config.js:强制 unstable_serverRoot 指向 projectRoot,解决 Windows 上 Gradle 入口文件相对路径与 Metro serverRoot 不一致的 bug;补充 monorepo watchFolders 和 nodeModulesPaths 配置
- CLAUDE.md 补充命令执行规则,明确 bash 语法优先、禁止输出命令让用户手动执行

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-10 23:02:15 +09:00

35 lines
1.3 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const { getDefaultConfig } = require('expo/metro-config')
const path = require('path')
const projectRoot = __dirname
const monorepoRoot = path.resolve(projectRoot, '../..')
const config = getDefaultConfig(projectRoot)
// 修复 Windows 上 release 构建的路径问题:
// RN Gradle 插件在 Windows 上把 entryFile 转为相对于 apps/property-survey 的路径
// (如 ../../node_modules/expo-router/entry.js),但 @expo/metro-config 的
// getDefaultConfig 会把 unstable_serverRoot 设为 monorepo 根目录,
// 导致 Metro 从错误的基准解析相对路径。
// 强制 unstable_serverRoot 为 projectRoot使两者基准一致。
config.server = {
...config.server,
unstable_serverRoot: projectRoot,
}
// 让 Metro 监听 monorepo 根目录,确保根 node_modules 可被解析
config.watchFolders = [monorepoRoot]
// 模块解析路径:先查 app 自己的 node_modules再查 monorepo 根的 node_modules
config.resolver.nodeModulesPaths = [
path.resolve(projectRoot, 'node_modules'),
path.resolve(monorepoRoot, 'node_modules'),
]
// SVG 作为普通资产文件处理(不经过 transformer 编译,避免大文件解析超限)
if (!config.resolver.assetExts.includes('svg')) {
config.resolver.assetExts.push('svg')
}
module.exports = config