macos下搭建react native 开发环境

macos下搭建react native 开发环境

  • 安装依赖
    • 安装步骤
      • 1.安装homebrew
      • 2.按照node和watchman
      • 3.切换淘宝源
      • 4安装yarn
      • 5安装xcode
      • 6创建react native 项目
      • 7运行项目

安装依赖

必须安装的依赖有:Node、Watchman、Xcode和CocoaPods。

安装步骤

1.安装homebrew

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

2.按照node和watchman

brew install node
brew install watchman

3.切换淘宝源

# 使用nrm工具切换淘宝源
npx nrm use taobao
# 如果之后需要切换回官方源可使用
npx nrm use npm

4安装yarn

npm install -g yarn

5安装xcode

在appstore直接下载xcode即可

6创建react native 项目

npx react-native init FirstApp

运行时会报错如下图
macos下搭建react native 开发环境_第1张图片
使用国内的一个镜像下载cocoapods镜像

$ cd ~/.cocoapods/repos 
$ pod repo remove master
$ git clone https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git master

下载好cocoapods镜像后在FirstApp/ios的podFile第一行加上:

source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'

注意一定要用xcode打开编辑!
然后按照提示进入的Firstapp/ios下执行命令

pod install

如果没执行成功过的话,换成4g网下图是成功截图
macos下搭建react native 开发环境_第2张图片

7运行项目

在项目目录下即FirstApp下执行

yarn ios

macos下搭建react native 开发环境_第3张图片

你可能感兴趣的:(react,native,react,native)