react natvie学习与实践(1)基础配置

在这里插入图片描述

环境搭建

按照官网的中文指引文档即可
搭建开发环境

工程构建

使用react-native init 命令来创建一个RN工程,如下所示

# 工程目录名是驼峰命名规则
react-native ini helloRN

成功创建后有如下提示,运行应用(推荐使用VS code来打工工程)

Run instructions for iOS:
    • cd /Users/luogw/temp/helloRN && react-native run-ios
    - or -
    • Open ios/helloRN.xcodeproj in Xcode
    • Hit the Run button

  Run instructions for Android:
    • Have an Android emulator running (quickest way to get started), or a device connected.
    • cd /Users/luogw/temp/helloRN && react-native run-android

基础CLI命令

管理依赖

 # 重新安装node_modules
npm install
# 添加依赖 react-native-vector-icons
npm install react-native-vector-icons
# 移除依赖库(如果做了link的依赖,行移除前,先进行unlink,然后才能进行移除操作
npm uninstall react-native-vector-icons 
# 链接所有可以自动链接的依赖库
react-native link
# 链接某个依赖 如 react-native-vector-icons
react-native link react-native-vector-icons
# 断开链接单个依赖:react-native-vector-icons
react-native unlink react-native-vector-icons
# 移除 node_modules
rm -rf node_modules

应用打包


react-native命令

luogw@luogw-mbp studyRN$ react-native --help
Usage: react-native [options] [command]

Options:
  --version                          Print CLI version
  --projectRoot [string]             Path to the root of the project
  --reactNativePath [string]         Path to React Native
  --verbose                          Increase logging verbosity
  -h, --help                         output usage information

Commands:
  start [options]                    starts the webserver
  run-ios [options]                  builds your app and starts it on iOS simulator
  run-android [options]              builds your app and starts it on a connected Android emulator or device
  new-library [options]              generates a native library bridge
  bundle [options]                   builds the javascript bundle for offline use
  ram-bundle [options]               builds javascript as a "Random Access Module" bundle for offline use
  eject [options]                    Re-create the iOS and Android folders and native code
  link [options] [packageName]       scope link command to certain platforms (comma-separated)
  unlink [options] <packageName>     unlink native dependency
  install [options] <packageName>    install and link native dependencies
  uninstall [options] <packageName>  uninstall and unlink native dependencies
  upgrade [options] [version]        Upgrade your app's template files to the specified or latest npm version using `rn-diff-purge` project. Only valid semver versions are allowed.
  log-android [options]              starts adb logcat
  log-ios [options]                  starts iOS device syslog tail
  dependencies [options]             lists dependencies
  info [options]                     Get relevant version info about OS, toolchain and libraries
  init [options]

调试技巧

官网开发调试指引

引入第三方库

引入第二方库,有些是库是需要引入本地资源的,需要react-native link相关的资源
如引入react-native-elements库时
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值