全局安装 yarn(Yarn是facebook发布的一款取代npm的包管理工具)
npm install yarn -g
查看版本号:
yarn --version
使用脚手架初始化一个项目的步骤
-
安装相关的脚手架:create-react-app
执行全局安装命令:
yarn global add create-react-app
或
npm install create-react-app -g
-
使用初始化命令,初始化一个项目
命令:
create-react-app 项目名称
执行初始化命令可能会失败,这时可以使用如下命令来初始化项目:
npx create-react-app 项目名称
执行该命令需要注意的是:Node 的版本不能低于 8.10 和 npm 的版本不低于 5.6
npx create-react-app 命令执行的过程:
(1)安装脚手架
yarn global add create-readt-app
(2)初始化项目
create-react-app 项目名称
(3)移除脚手架
yarn remove create-react-app
-
启动项目
进入项目的根目录,执行如下命令启动项目:
yarn start