通过关闭CI的Flipper来加快iOS构建(完整的React本地指南)
#reactnative #ios #ci #flipper

加快pod install加速的简单方法是关闭CI构建的flipper。

1)对于旧react本机版本0.68.x和lows编辑您的ios/Podfile

# ./ios/Podfile
if !ENV['CI']
  use_flipper!()
end

2)对于React Native 0.69.x...0.70.x

# ./ios/Podfile
use_react_native!(
  :flipper_configuration => ENV['CI'] ?
    FlipperConfiguration.disabled : 
    FlipperConfiguration.enabled,
  # ...
  # Note: you also can pass extra params
  # FlipperConfiguration.enabled(['Debug', 'Staging.Debug'], { 'Flipper': '0.174.0' })
)

3)如果您使用的是现代的React Native koude4及更高及更高及更高版

export NO_FLIPPER=1
pod install --project-directory=ios
# or short
NO_FLIPPER=1 pod install --project-directory=ios

故障排除

如果您的iOS构建将失败,下一个错误

node_modules/react-native-flipper/ios/FlipperReactNativeJavaScriptPlugin.h:9:9: 'FlipperKit/FlipperConnection.h' file not found

#import <FlipperKit/FlipperConnection.h>

它发生了,因为react-native-flipper包需要安装的FlipperKit pod,但我们将其关闭。

解决方案很容易,只需在CI上排除该模块,您需要在项目的根文件夹中编辑/添加react-native.config.js

// react-native.config.js
module.exports = {
  dependencies: {
    ...(process.env.CI // or `process.env.NO_FLIPPER` for RN@0.71.x and above
      ? { 'react-native-flipper': { platforms: { ios: null } } }
      : {}),
  },
  project: {
    ios: {},
    android: {},
  },
};