Skip to content

一. 官网

Create React App

二. 使用

React脚手架本身需要依赖node,所以我们需要安装node环境
You’ll need to have Node >= 14 on your local development machine

1. Creating an App

1. 使用npx

cpp
npx create-react-app my-app

2. 使用npm

cpp
npm init react-app my-app

3. 使用yarn

cpp
yarn create react-app my-app

2. Selecting a template

1. 创建普通模板项目

cpp
npx create-react-app my-app --template [template-name]

2. 创建TypeScript项目

cpp
npx create-react-app my-app --template typescript

三. 目录结构分析

image.pngimage.png

四. 脚本

1. 启动项目

cpp
npm start  
// or
yarn start

2. 打包

cpp
npm run build
// or
yarn build

3. 释放webpack配置

我们可以执行一个package.json文件中的一个脚本:"eject": "react-scripts eject"
这个操作是不可逆的,所以在执行过程中会给与我们提示;

cpp
yarn eject

基于 MIT 许可发布