1. Complexity of front-end engineering
Modern front-end projects have become increasingly complex:
In order to solve the above problems, we need to learn some more tools:
2. What is scaffolding?Traditional scaffolding refers to a structure in architecture: a temporary frame built when constructing a building or structure; The scaffold mentioned in programming is actually a tool that helps us quickly generate the engineering structure of the project;
Summary: Scaffolding makes the entire process from project construction to development and then to deployment fast and convenient; 3. Front-end scaffoldingThe three most popular frameworks now all have their own scaffolding:
Their role is to help us generate a common directory structure and configure the engineering environment we need.
Here we are mainly learning React, so we still use React's scaffolding tool: create-react-app as an explanation; 4. Install nodeReact scaffolding itself needs to rely on node, so we need to install the node environment: Whether it is Windows or Mac OS, you can download it directly from the node official website; Official website address: https://nodejs.org/en/download/ Note: It is recommended that you download the LTS (Long-term support) version, which is a long-term support version and will be more stable; After downloading, double-click to install: Enter the following command: node --version npm --version If the version number appears, it means the installation was successful. 5. Package Management ToolsWhat is npm?
In addition, there is a well-known node package management tool yarn:
npm install -g yarn Enter 6. Comparison of Yarn and npm commands7. Install scaffolding Supplement: In China, in some cases, using npm and yarn may not be able to install a library properly. At this time, we can choose to use npm install -g cnpm --registry=https://registry.npm.taobao.org The last thing you need to install is the scaffolding for creating a React project: npm install -g create-react-app Enter 8. Create a React projectNow, we can create a React project through scaffolding. The command to create a React project is as follows: Note: Project names cannot contain uppercase letters. There are more ways to create projects, please refer to GitHub's readme create-react-app Project Name After the creation is complete, enter the corresponding directory and run the project: cd 01-test-reactyarn start 9. Directory structure analysis10. Understand PWAThe entire directory structure is very easy to understand, except for the concept of PWA:
What problems does PWA solve?
11. What is webpackWe said that React's scaffolding is configured based on Webpack:
12. Webpack in Scaffolding We will not discuss webpack here, because there is a lot of content (there will be a special topic on webpack later); The reason is that the React scaffolding hides the webpack-related configuration (in fact, it has also been hidden since Vue CLI3); If we want to see the configuration information of webpack, what should we do?
yarn eject 13. Webpack in Scaffolding14. File structure deletion After creating the project through scaffolding, many students still feel that the directory structure is too complicated, so I plan to lead everyone to write code from scratch. Delete all files under src. Delete all files except favicon.ico and index.html under public. 15. Start writing code In the src directory, create an index.js file, because this is the entry point for webpack packaging. We will find that the logic of the code is consistent with what we wrote; it’s just that in modular development, we need to manually import React and ReactDOM because they are in the modules we installed; If we don't want to write too much code directly in ReactDOM.render, we can extract a component App.js separately: This is the end of this article about learning how to build React scaffolding. For more relevant React scaffolding content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Summary of some HTML code writing style suggestions
>>: An example of using Dapr to simplify microservices from scratch
Table of contents Preface What is a virtual list?...
The smallest scheduling unit in k8s --- pod In th...
Table of contents 1. What is a custom instruction...
What are the attributes of the JS script tag: cha...
This is a collection of commonly used but easily ...
Table of contents Preface 1. What is selenium? 2....
Table of contents 1. Scene layout 2. Add a handle...
This tutorial shares the specific code of MySQL5....
SMIL adds support for timing and media synchroniz...
This article shares the data display code for Jav...
Preface : Today I was asked, "Have you carefu...
MySQL-Group-Replication is a new feature develope...
Copy code The code is as follows: <!DOCTYPE ht...
The default time type (datetime and timestamp) in...
This tutorial shares the detailed steps of instal...