


Detailed steps to build a React development environment using create-react-app
This time I will give you a detailed explanation of the steps to use create-react-app to build a React development environment. What are the precautions for using create-react-app to build a React development environment. The following is a practical case. Let’s take a look.
Commonly used scaffolding
react-boilerplate
react- redux-starter-kit
create-react-app (most followed on git)
Use create- react-app quickly builds a React development environment
create-react-app comes from Facebook. With this command, we can quickly build a React development environment without configuration.
create-react-app The automatically created project is based on Webpack ES6.
Execute the following commandCreate project:
$ cnpm install -g create-react-app $ create-react-app my-app $ cd my-app/ $ npm start
tips:
If using npm is very slow, you can use Taobao’s customized cnpm (gzip compression Support) command line tool instead of the default npm:
$ npm install -g cnpm --registry=https://registry.npm.taobao.org $ npm config set registry https://registry.npm.taobao.org
How to compile less
1. Expose the configuration file
npm run eject
2.Installless-loader and less
npm install less-loader less --save-dev
3. Modify webpack configuration
Modify webpack.config.dev.js and webpack. config-prod.js configuration file
test: /\.css$/ 改为 /\.(css|less)$/
Find use under this test, add loader
{ loader: require.resolve('less-loader') // compiles Less to CSS }
Okay, re-run the project less has been compiled
Project structure
src directory
The src directory is used to store our own code. You can create subdirectories under src, only src Files in the root directory will be compiled by webpack, so the files must be placed in the src root directory, otherwise they will not be recognized.
public directory
Only files in the public directory will be referenced by public/index.html
tip: index under public and src. The html file must exist and cannot be renamed
Common commands
1Start command
npm start
2Compile and package command. Compile the code in the production environment and place it in the build directory to correctly package the code, optimize, compress, and use hash to rename the file
npm run build
3. Test after the file is modified
npm test
4 .structure command. The configuration command of webpck is exposed. Originally in the scaffolding, the configuration item is invisible and needs to be modified before executing this command (this is a single command, once structured, it is irreversible.)
npm run eject
5.httpsRun
set HTTPS=true&&npm start
6. Online compilation
This is a big highlight of create-react-app. It allows your application to decode the code and compile the files that run in the online production environment. It is very small, and the file name also has a hash value, which is convenient for us to cache, and it also provides a server so that we can see similar effects to the online production environment locally, which is really super convenient.
Just one line of command:
npm run build
7.api development
Just add a configuration item to the package.json file.
"proxy": http://localhost:3001/,
8.ajax?
Instead of using fetch
npm install whatwg-fetch
import 'whatwg-fetch' fetch('/power-mnjy-mobile/intf/h5/user/login?mobile=13000000001&pwd=a111111&ignoreCsrfToken=true') .then(res => res.json()) .then((data) => { this.setState({ value:data }); });
Debugging tool react developer tools (https://github.com/facebook/react-devtools)
Add the extension react developer tools in chrome, remember Restart the browser (restart, restart, restart, say important things three times), and the react option will appear in the chrome development tools.
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
How to use AngularJS to implement tab switching
How to use Koa2 to develop WeChat 2D Scan the QR code to pay
The above is the detailed content of Detailed steps to build a React development environment using create-react-app. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



This AI-assisted programming tool has unearthed a large number of useful AI-assisted programming tools in this stage of rapid AI development. AI-assisted programming tools can improve development efficiency, improve code quality, and reduce bug rates. They are important assistants in the modern software development process. Today Dayao will share with you 4 AI-assisted programming tools (and all support C# language). I hope it will be helpful to everyone. https://github.com/YSGStudyHards/DotNetGuide1.GitHubCopilotGitHubCopilot is an AI coding assistant that helps you write code faster and with less effort, so you can focus more on problem solving and collaboration. Git

On March 3, 2022, less than a month after the birth of the world's first AI programmer Devin, the NLP team of Princeton University developed an open source AI programmer SWE-agent. It leverages the GPT-4 model to automatically resolve issues in GitHub repositories. SWE-agent's performance on the SWE-bench test set is similar to Devin, taking an average of 93 seconds and solving 12.29% of the problems. By interacting with a dedicated terminal, SWE-agent can open and search file contents, use automatic syntax checking, edit specific lines, and write and execute tests. (Note: The above content is a slight adjustment of the original content, but the key information in the original text is retained and does not exceed the specified word limit.) SWE-A

Go language development mobile application tutorial As the mobile application market continues to boom, more and more developers are beginning to explore how to use Go language to develop mobile applications. As a simple and efficient programming language, Go language has also shown strong potential in mobile application development. This article will introduce in detail how to use Go language to develop mobile applications, and attach specific code examples to help readers get started quickly and start developing their own mobile applications. 1. Preparation Before starting, we need to prepare the development environment and tools. head

PHP, Vue and React: How to choose the most suitable front-end framework? With the continuous development of Internet technology, front-end frameworks play a vital role in Web development. PHP, Vue and React are three representative front-end frameworks, each with its own unique characteristics and advantages. When choosing which front-end framework to use, developers need to make an informed decision based on project needs, team skills, and personal preferences. This article will compare the characteristics and uses of the three front-end frameworks PHP, Vue and React.

Android development is a busy and exciting job, and choosing a suitable Linux distribution for development is particularly important. Among the many Linux distributions, which one is most suitable for Android development? This article will explore this issue from several aspects and give specific code examples. First, let’s take a look at several currently popular Linux distributions: Ubuntu, Fedora, Debian, CentOS, etc. They all have their own advantages and characteristics.

Integration of Java framework and React framework: Steps: Set up the back-end Java framework. Create project structure. Configure build tools. Create React applications. Write REST API endpoints. Configure the communication mechanism. Practical case (SpringBoot+React): Java code: Define RESTfulAPI controller. React code: Get and display the data returned by the API.

As a fast and efficient programming language, Go language is widely popular in the field of back-end development. However, few people associate Go language with front-end development. In fact, using Go language for front-end development can not only improve efficiency, but also bring new horizons to developers. This article will explore the possibility of using the Go language for front-end development and provide specific code examples to help readers better understand this area. In traditional front-end development, JavaScript, HTML, and CSS are often used to build user interfaces

"Understanding VSCode: What is this tool used for?" 》As a programmer, whether you are a beginner or an experienced developer, you cannot do without the use of code editing tools. Among many editing tools, Visual Studio Code (VSCode for short) is very popular among developers as an open source, lightweight, and powerful code editor. So, what exactly is VSCode used for? This article will delve into the functions and uses of VSCode and provide specific code examples to help readers
