这些 React Native 启动命令有什么区别? [英] What are the difference between these React Native start commands?

查看:66
本文介绍了这些 React Native 启动命令有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用 React Native 几个月了.但是,我真的不知道启动命令之间的区别.目前,我在我的项目中使用 npm.但是,我知道可以使用纱线.这些是我真的不明白它们之间的区别的命令:

I have been using react native for a couple months now. However, I really don't know the difference between the starting commands. Currently, I use npm on my project. However, I know yarn can be used. These are the commands I really don't understand the difference with:

exp 开始,exp ios,exp android

exp start, exp ios, exp android

react-native run-ios、react-native run-android

react-native run-ios, react-native run-android

npm 开始、npm ios、npm android

npm start, npm ios, npm android

在什么情况下哪个更好,为什么?目前,我使用 exp,但其他人使用 react-native run-ios.我以前用的是 npm ios.

Which ones are better in what cases and why? Currently, I am using exp but others use react-native run-ios. I used to use npm ios.

提前致谢.

推荐答案

了解 React Native 架构.

在 react native 中,当您编写 <View/> 时,它会通过桥发送到本机代码并动态转换为 UIViewiOS 或 Android 上的 android.view.View.react-native 包中的每个基本组件都以这种方式实现.如果您希望在两个平台上都有额外的本机功能,例如使用本机地图组件的库,您最终必须将本机库分别包含到您的 Android build.gradle 和 iOS 中.xcodeproj.

In react native, when you write, say, <View/>, it gets sent across the bridge to the native code and dynamically translated into UIView on iOS or android.view.View on Android. Every basic component in the react-native package has been implemented this way. If you want additional native functionality on both platforms, say a library which uses native map components, you will end up having to include the native libraries separately into your Android build.gradle and your iOS .xcodeproj.

exp CLI 用于启动使用 Expo SDK.Expo 本质上是一个预先构建的应用程序,为方便起见,已经包含了一组特定的本地组件;你提供的只是你的 JSX;因此,如果您需要使用任何其他库,建议弹出"到常规的 React Native 应用程序.

The exp CLI is used to start apps built with the Expo SDK. Expo is essentially a prebuilt app with a certain set of native components already included for convenience; all you supply is your JSX; thus the recommendation to "eject" to a regular react native app if you need to use any other libraries.

react-native run-iosrun-android 构建原生 .app.apk 使用iOS 或 Android 工具链,启动 Metro Bundler,它会在调试模式下缩小 JSX 和其他资产(例如图像)并将其提供给您的设备(您可能会看到类似 Loading from localhost:8081 的内容).

react-native run-ios and run-android builds the native .app or .apk using the iOS or Android toolchains, starts the Metro Bundler, which minifies and serves the JSX and other assets such as images over to your device in debug mode (You might see something like Loading from localhost:8081).

在 Android 上,如果您启用了 USB 调试,它会启动 adb 服务器以将包含所有本机库的 APK 推送到您的设备上.run-ios.app 做同样的事情;如果您安装到模拟器,它会自动配置 AppDelegate.m 以与 localhost:8081 通信,而通过 USB 的实时重新加载必须在物理设备上手动配置.

On Android, it starts the adb server to push the APK with all the native libraries included onto your device, if you have USB debugging enabled. run-ios does the same with the .app; if you install to a simulator it has automatically configured AppDelegate.m to communicate with localhost:8081, whereas live reload over USB has to be configured manually on a physical device.

react-native start 只是启动 Metro 捆绑器,如果您已经安装了应用程序,这很有用.

react-native start simply starts the Metro bundler, which is useful if you already have the app installed.

npm 开头的命令被定义为 package.json 文件中的脚本.从 RN 0.57 开始,npm start 只调用 node node_modules/react-native/local-cli/cli.js start;这与运行 react-native start 相同;根据文档 react-native-cli 单独安装将调用 node_modules 中本地安装的 CLI 版本.

Commands that begin with npm are defined as scripts in your package.json file. As of RN 0.57, npm start simply calls node node_modules/react-native/local-cli/cli.js start; which is the same as running react-native start; according to the docs react-native-cli installed separately will call the locally installed version of the CLI in node_modules.

这篇关于这些 React Native 启动命令有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆