ReactNative 常用命令

本文介绍了ReactNative的常用命令,包括初始化项目、配置淘宝镜像、安装和卸载组件、链接依赖、打包和运行项目等步骤,帮助开发者更高效地管理ReactNative项目。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ReactNative 常用命令

安装RN的初始化命令

npm install -g react-native-cli

配置淘宝镜像
npm config set registry https://registry.npm.taobao.org
npm config set disturl https://npm.taobao.org/dist

初始化某个版本
react-native init rnAndroid --version 0.59.10 //注意版本号必须精确到两个小数点。

移除node_modules 和package-lock.json

remove node_modules and package-lock.json

重新下载node_modules

npm install

引用某个组件

npm install react-navigation --save

npm install react-navigation@14.5.2 --save
等效
npm install react-navigation@14.5.2 -S

npm install react-navigation --save
等效
npm install react-navigation@14.5.2 -D

自动链接单个依赖
react-native link react-native-camera

自动链接所有的依赖库

react-native link

删除引用组件:

react-native unlink react-native-baidu-map
npm uninstall react-native-baidu-map --save

添加组件
yarn add xxx@0.31.0
npm install xxx@031.0 --sava

yarn add xxx@0.31.0 --dev
npm install xxx@031.0 --sava-dev

移除组件
yarn remove xxx@0.31.0
npm uninstall xxx@0.31.0 --save

运行项目:

react-native run-android

react-native run-ios

或者yarn android 或yarn ios

查看链接设备:

adb devices

查看reactnative版本

react-native --version

打包ios:

react-native bundle --entry-file index.js --bundle-output ./ios/bundle/index.ios.jsbundle --platform ios --assets-dest ./ios/bundle --dev false

android 打包是通过先打包bundle

react-native bundle --entry-file index.js --platform android --dev false --bundle-output ./android/app/src/main/assets/index.android.bundle --assets-dest ./android/app/src/main/res

然后到android目录下在打包

cd android //进入到android项目目录
./gradlew clean //先清除打包缓存
./gradlew assembleDebug //打debug环境apk
./gradlew assembleRelease //打release环境apk

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值