怎么用 NPM 装 react? 下面本篇文章就来给大家介绍一下使用 NPM 安装 react 的方法. 有一定的参考价值, 有需要的朋友可以参考一下, 希望对大家有所帮助.
用 NPM 安装 react 的步骤:
步骤 1: 确保你电脑上安装了最新版本的 Node.JS.[Node.JS 安装教程 https://www.html.cn/qa/node-js/10676.html ]
步骤 2: 安装淘宝镜像 (国内使用 NPM 速度很慢, 你可以使用淘宝定制的 cnpm (gzip 压缩支持) 命令行工具代替默认的 NPM)
使用淘宝镜像提供的 cnpm 工具, 通过 cnpm 来安装包一般速度会更快一些, 我们可以直接复制文档中的命令:
- $ NPM install -g cnpm --registry=https://registry.npm.taobao.org
- $ NPM config set registry https://registry.npm.taobao.org
这样就可以使用 cnpm 命令来安装模块了:
$ cnpm install [name]
步骤 3: 使用 create-react-App 快速构建 React 开发环境
create-react-App 是来自于 Facebook, 通过该命令我们无需配置就能快速构建 React 开发环境.
create-react-App 自动创建的项目是基于 webpack + ES6 .
执行以下命令创建项目:
- $ cnpm install -g create-react-App
- $ create-react-App my-first-react-App
- $ cd my-first-react-App/
- $ NPM start
更多 react 相关知识, 可访问 react 教程 https://www.html.cn/qa/react/ 栏目!!
来源: http://www.css88.com/qa/react/14370.html