1. 准备阶段
npm更换淘宝镜像
$ npm install -g cnpm --registry=https://registry.npm.taobao.org
$ npm config set registry https://registry.npm.taobao.org
这样就可以用cnpm来安装模块了,速度会快很多!亲身经历!
$ cnpm install [name]
2. 使用create-react-app快速构建React
在想要创建项目的地方
npx create-react-app order-list
order-list为项目名,最开始我使用了orderList,报错
这样就创建好了order-list的项目,转到order-list文件夹下,运行npm start
启动项目,会自动打开 http://localhost:3000/ 展示起始页面。一个简单的react项目就完成了。
npm start
3. 项目结构
项目结构如下所示:
主要代码放在src下,public主要放静态资源,这些静态资源是不会参与webpack的构建的。
src下创建一个components文件夹用于存放组件,每一个组件又单独创建一个文件夹来进行包装