[英]How can i create new react native App using npx?
I didn't use react-native for a few months.我有几个月没有使用 react-native 了。 It looks like some things have changed meanwhile.
看起来有些事情同时发生了变化。 In the official documentation they recommend to uninstall
react-native-cli
and to use npx react-native init
instead.在官方文档中,他们建议卸载
react-native-cli
并改用npx react-native init
。 I did this but ended up with an error because I didn't install that package globally.我这样做但最终出现错误,因为我没有在全球范围内安装 package。 However, if I install
react-native
globally, it results in an error when I run the project, saying that I should remove the global package.但是,如果我全局安装
react-native
,运行项目时会报错,提示我应该去掉全局的package。
What is the proper way to create a react app nowadays?现在创建 React 应用程序的正确方法是什么?
npx react-native init ProjectName
to create new projectnpx react-native init ProjectName
创建新项目yarn react-native run-android
or yarn react-native run-ios
to run the projectyarn react-native run-android
或yarn react-native run-ios
来运行项目@Raeygzz if you want to use react-native related command add yarn/npx in the beginning of the command @Raeygzz 如果你想使用 react-native 相关命令在命令的开头添加 yarn/npx
yarn react-native run-android
yarn react-native run-ios
or或者
npx react-native run-android
npx react-native run-ios
if you want to create apk debug use in your root project如果你想在你的根项目中创建 apk 调试使用
cd android && gradlew assembleDebug cd android && gradlew assembleDebug
apk release in your root project在您的根项目中发布 apk
cd android && gradlew assembleRelease cd android && gradlew assembleRelease
Debug with bundle in your root project在根项目中使用 bundle 进行调试
yarn react native run-android纱线反应本机运行Android
and get the apk file in并获取apk文件
android\app\build\outputs\apk\debug
i usually do this if the device i working on doesn't have an usb cable, so i copy the file there, and sent it to the cloud, download it to device and install it, after that i just shake the phone and go to settings and setup debug server ex: 10.xxx.xxx:8081 then run yarn start in cmd shake the device and choose refresh如果我使用的设备没有 USB 电缆,我通常会这样做,所以我将文件复制到那里,然后将其发送到云端,将其下载到设备并安装它,然后我只需摇晃手机并转到设置和设置调试服务器例如:10.xxx.xxx:8081 然后在 cmd 中运行 yarn start 摇动设备并选择刷新
the difference is here between react-native run-android and gradlew assembleDebug react-native run-android Vs ./gradlew assembleDebug不同之处在于 react-native run-android 和 gradlew assembleDebug react-native run-android Vs ./gradlew assembleDebug
查看他们的官方文档npx
Thanks @Gus Nando for the detail... and if i want to make a debug build for android using npx then what should i follow.感谢@Gus Nando 提供的详细信息……如果我想使用 npx 为 android 进行调试构建,那么我应该遵循什么。 And also if there is any changes or change in set of way to create debug as well as production build for both android and ios platform.
此外,如果为 android 和 ios 平台创建调试和生产构建的方式有任何更改或更改。
Any kind of info related to npx will be of much help.任何与 npx 相关的信息都会有很大帮助。 Thanks in advance
提前致谢
The first thing you need to do is delete react-native-cli:您需要做的第一件事是删除react-native-cli:
npm uninstall react-native-cli
or npm uninstall --global react-native-cli
npm uninstall react-native-cli
或npm uninstall --global react-native-cli
Then, install Expo CLI if you have NodeJS 10 LTS or greater installed: npm install -g expo-cli
然后,如果您安装了 NodeJS 10 LTS 或更高版本,请安装 Expo CLI:
npm install -g expo-cli
You should be able to make new react native app now with expo-cli like that : expo init ProjectName
您现在应该能够使用 expo-cli 制作新的 React Native 应用程序,如下所示:
expo init ProjectName
Expo is a tool that allows you to set up a development environment on your phone. Expo 是一种工具,可让您在手机上设置开发环境。 For more information, see the documentation here: https://expo.io/
有关更多信息,请参阅此处的文档: https : //expo.io/
It is the most efficient and fastest way to develop, test and deploy an application它是开发、测试和部署应用程序的最有效、最快捷的方式
尝试使用npx react-native init projectName
然后使用cd projectName
将目录更改为项目并使用react-native run-android
运行项目
it's easy: in case of developing in windows just do the following command in your prefered terminal with administrative access: npx react-native init YourPrjName这很简单:如果在 windows 中进行开发,只需在具有管理权限的首选终端中执行以下命令:npx react-native init YourPrjName
for details take a look at this brief video https://youtu.be/A5pXsiBVKTY有关详细信息,请观看此简短视频https://youtu.be/A5pXsiBVKTY
and don't forget to use lower case except for project name并且不要忘记使用小写字母,除了项目名称
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.