[React Family Bucket] Know and use React scaffolding to create React projects

1. Use create-react-app to initialize React scaffolding

1. Introduction to react scaffolding

1. The role is to help programmers quickly build template projects
2. React provides a scaffolding library for creating react projects: create-react-app
3. The overall technical architecture of the project is react+webpack+es6+eslint
4. Features: Modularization, componentization, engineering

2. Create a project and start

npm install the repository globally: npm i -g create-react-app
Use the create-react-app command to create a new project: create-react-app hello-react Go
to the project folder: cd hello-react
Start the project: npm start

insert image description here

3. File directory description

insert image description here

insert image description here

2. Simplify project documents

(1)删除public和src文件夹里的内容
(2)在public中新建index.html文件

<!--index.html-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <!-- %PUBLIC_URL%表示public文件夹的路径 -->
    <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
    <!-- 开启理想视口,用于做移动端网页的适配 -->
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>React App</title>
  </head>
  <body>
    <noscript>You need to enable JavaScript to run this app.</noscript>
    <div id="root"></div>
  </body>
</html>

(3)安装vscode扩展:ES7+ React/Redux/React-Native snippets

(4)在src文件夹下新建App.jsx或者App.js文件,输入快捷命令:rcc

//App.js
//输入rcc 或者rfc ,快捷生成函数式或类式组件
import React, {
    
     Component } from 'react';

export default class APP extends Component {
    
    
  render() {
    
    
    return <div>Hello React</div>;
  }
}

(5)在src文件夹下新建index.js文件

//index.js
import React from "react";
import ReactDOM from "react-dom";
import App from "./App";

ReactDOM.render(
    <App />,
    document.getElementById('root')
  );

(6)在终端使用npm start运行
insert image description here

The above is the content of using React scaffolding to create a React project. Please pay attention to the " React Family Bucket " column.
I will share the common problems in my usual projects and the knowledge of the written test and interview with you on CSDN, and make progress together. Come on.

Guess you like

Origin blog.csdn.net/weixin_46318413/article/details/122607873