React-native 安装基础篇
RN官方文档 (0.55):
RN
中文翻译
文档 (0.51):
推荐博客
ES6
语法学习(阮一峰)
以下基于MacOS
一、安装工具
1、 安装 homebre
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2、然后 安装 node.js
brew install node
3、 配置node
国内镜像
# (1)修改 下载仓库为淘宝镜像
npm config set registry https://registry.npm.taobao.org --global
#如果要发布自己的镜像需要修改回来
#npm config set registry https://registry.npmjs.org/
# (2)
npm config set disturl https://nodejs.org/dist/ --global
#是否配置成功,请使用下面命令
npm config get registry
npm config get disturl
#查看npm全部配置
npm config get
4、Yarn、React Native的命令行工具(react-native-cli)
# Yarn是Facebook提供的替代npm的工具,可以加速node模块的下载。
# React Native的命令行工具用于执行创建、初始化、更新项目、运行打包服务(packager)等任务。
npm install -g yarn react-native-cli
# 配置` Yarn `国内镜像
yarn config set registry https://registry.npm.taobao.org --global
yarn config set disturl https://npm.taobao.org/dist --global
二、安装、配置 RN
1、下载 RN
# 第1️⃣种 -> 第一次新项目空文件安装
react-native init <项目名>
# ------------------------------------
# 第2️⃣种 -> 在原生项目基础上安装
# (2-1)新建 `RN工程文件夹` 后 `终端`定位到该文件夹(cd ...),copy 项目 到建立 `/ios` 文件夹
# https://reactnative.cn/docs/0.51/integration-with-existing-apps.html#content
# (2-2)在项目根目录下创建一个名为package.json的空文本文件
touch package.json # 或者copy 一个也行,但要看配置
# (2-3) `package.json`为空,需要填写将要安装的&#