从终端运行React Native iOS发布版本的构建

52

我想直接从终端运行发布版,但没有找到相应的选项。

在XCode中需要执行以下步骤:

选择Product -> Scheme -> Edit Scheme (cmd + <),确认当前在侧边栏的Run标签下,并将Build Configuration下拉菜单设置为release。

http://facebook.github.io/react-native/docs/running-on-device-ios.html#building-your-app-for-production

react-native-cli中是否有类似于react-native run-ios -configuration Release的选项呢?

我的目标是生成一个构建版本,不需要服务器运行就可以提供给QA团队等。

6个回答

140

我向React Native项目发起了一次Pull Request,以添加此功能。PR可以在此处检查:https://github.com/facebook/react-native/commit/ca7cbdee858e84c4a74a2d9c7be151f5cfdcfbfe

因此,未来只需在终端中键入以下命令即可运行发布版本构建:npx react-native run-ios --configuration Release

如果要在真实设备上运行项目,请使用--device参数:

npx react-native run-ios --configuration Release --device "Your Device Name"

1
谢谢。需要升级到v0.39+。 - Hulvej
1
是的,自v0.39版本以来就可用。 - Sandro Machado
1
嗯,要生成二进制文件以上传到AppStore/在设备上安装,您需要执行以下操作:https://dev59.com/sFgQ5IYBdhLWcg3w3Hp-#42130914 - Sandro Machado
2
对我来说,它在模拟器上运行。我怎样才能将其定位到我的设备? - Peter Borbas
1
非常感谢,但对我来说不起作用 :( - famfamfam
显示剩余4条评论

10

2023年5月

更新一下:已经弃用configuration,改用mode

npx react-native run-ios --mode Release


1
这应该是被接受的答案。 - undefined

2

刚刚检查过了,它可以正常工作:

npx react-native run-ios --configuration Release --simulator="iPhone 14"


1
简单易懂,只需运行命令即可。
npx react-native run-ios --mode Release

0

0

处理打包的 React Native 脚本在这里:

  ./node_modules/react-native/scripts/react-native-xcode.sh

它基本上就是这样做的:

  node "./node_modules/react-native/cli.js" bundle  --entry-file "index.js" --platform ios --dev false --reset-cache --bundle-output "./app.app/main.jsbundle" --assets-dest "./app.app"

其中bundle-output和asset-dest通常会指向您的Xcode构建输出目录。例如:

~/Library/Developer/Xcode/DerivedData/MyApp-enjmlvtpwwpnsxanntxwgpneywcy/Build/Intermediates.noindex/ArchiveIntermediates/MyApp/BuildProductsPath/Release-iphonesimulator/MyApp.app

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接