简体   繁体   English

如何使用 react-native cli 构建 react-native 应用程序?

[英]How to build react-native application with react-native cli?

I would wish to submit my react-native app to app store, but I don't know how to build it.我想将我的 react-native 应用程序提交到应用程序商店,但我不知道如何构建它。

I've been following this official doc of react-native ( http://reactnative.dev/docs/running-on-device#building-your-app-for-production ) about how to build my app for production, but sadly in my case it does not quite give enough information.我一直在关注 react-native 的官方文档( http://reactnative.dev/docs/running-on-device#building-your-app-for-production )关于如何构建我的生产应用程序,但遗憾的是在我的如果它没有提供足够的信息。

Regarding building an app, the guide says this:关于构建应用程序,该指南说:

You can now build your app for release by tapping ⌘B or selecting Product → Build from the menu bar.您现在可以通过点击 ⌘B 或从菜单栏中选择 Product → Build 来构建您的应用程序以供发布。 Once built for release, you'll be able to distribute the app to beta testers and submit the app to the App Store.一旦为发布而构建,您就可以将应用程序分发给 beta 测试人员并将应用程序提交到 App Store。

And I can do this.我可以做到这一点。 But the problem is, that I need to build my app with an ENVFILE environment variable that defines where my applications configurations are read from.但问题是,我需要使用 ENVFILE 环境变量来构建我的应用程序,该环境变量定义了从何处读取我的应用程序配置。

With this in mind, the official guide also states:考虑到这一点,官方指南还指出:

You can also use the React Native CLI to perform this operation using the option --configuration with the value Release (eg npx react-native run-ios --configuration Release).您还可以使用 React Native CLI 执行此操作,使用选项 --configuration 和值 Release(例如 npx react-native run-ios --configuration Release)。

This is almost what I want.这几乎就是我想要的。 But I don't want to run my app.但我不想运行我的应用程序。 I just want to build it.我只是想建造它。 So is there a way to build my app with the react-native cli tool?那么有没有办法使用 react-native cli 工具来构建我的应用程序? Without running it?不运行它? Or could I just run it and in the process it gets build and I could find the final build in some folder then?或者我可以运行它并在它构建的过程中然后我可以在某个文件夹中找到最终构建? Or if this doesn't work, could I then some way configure the ENVFILE environment variable to xcode that my app will get it?或者,如果这不起作用,那么我是否可以通过某种方式将 ENVFILE 环境变量配置为 xcode 以便我的应用程序能够获得它?

The react-native-config library build can be setup like below. react-native-config 库构建可以如下设置。

Step 1: Create a scheme for the project you can also use the existing ones第 1 步:为项目创建一个方案,您也可以使用现有的方案

Step 2: Go to edit scheme and chose pre-action under build from left menu步骤 2: Go 编辑方案并从左侧菜单中选择构建下的预操作在此处输入图像描述

Step 3: Provide echo '.env.yourenvironment' > /tmp/envfile in the script to run第 3 步:在脚本中提供echo '.env.yourenvironment' > /tmp/envfile以运行

This will run the script in the post build and copy the values to tmpfile which will be used by the library.这将在后期构建中运行脚本并将值复制到库将使用的 tmpfile。

Then you can normally archive or build the project using the scheme you created.然后,您通常可以使用您创建的方案归档或构建项目。

You can check these steps in the docs of the library as well.您也可以在库的文档中查看这些步骤。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM