通过npm使用react
首先node版本应该8.x及以上。
应注意,windows下无法使用npm命令升级node,而是直接从官网下载新版本覆盖安装旧版本。
由于国内使用npm速度比较慢,因此使用淘宝定制的cnpm
$ npm install -g cnpm --registry=https://registry.npm.taobao.org
$ npm config set registry https://registry.npm.taobao.org
使用create-react-app快速构建React开发环境
create-react-app来自于Facebook,通过该命令我们无需配置就可以快速构建React开发环境
create-react-app 自动创建的项目是基于webpack + ES6
执行以下命令创建项目
$ cnpm install -g create-react-app
$ create-react-app my-app
$ cd my-app/
$ npm start
create-react-app执行慢的解决方法
$ npm config set registry https://registry.npm.taobao.org
-- 配置后可通过下面方式来验证是否成功
$ npm config get registry
-- 或 npm info express