How to quickly set the file path alias in react

How to quickly set the file path alias in react

React is a JavaScript library for building user interfaces. It originated from an internal project of Facebook. Because the company was dissatisfied with all the JavaScript MVC frameworks on the market, it decided to write its own one to build the Instagram website. After it was developed, we found that this system was very useful, so we opened it to the public in May 2013.

React is a JAVASCRIPT library for building user interfaces.

React is mainly used to build UI, and many people think that React is the V (view) in MVC.

React originated as an internal project at Facebook, used to build Instagram's website, and was open sourced in May 2013.

React has high performance and very simple code logic, and more and more people have begun to pay attention to and use it.

Since webpack hides the configuration file, it needs to be exposed first. After entering the project directory, run the following code in cmd

npm run eject 

Are you sure you want to log out? This behavior is permanent.
Enter y and press Enter. After the run is completed, find the config folder in the project folder.

Open webpack.config.js

Press Ctrl+f to search for alias and find the configuration item

Configure the mapping, you can refer to the following configuration

alias: {
        "react-native": "react-native-web",
        ...(isEnvProductionProfile && {
          "react-dom$": "react-dom/profiling",
          "scheduler/tracing": "scheduler/tracing-profiling",
        }),
        ...(modules.webpackAliases || {}),
        // Configuration file alias, the alias is on the left and the corresponding path is on the right "@": path.resolve(__dirname, "../src"),
        "@scss": path.resolve(__dirname, "../src/assets/scss"),
        "@images": path.resolve(__dirname, "../src/assets/images"),
        "@views": path.resolve(__dirname, "../src/views"),
        "@components": path.resolve(__dirname, "../src/components"),
      },

After the configuration is complete, just restart the project.

This is the end of this article on how to quickly set file path aliases in react. For more relevant react file path aliases, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • How to configure path alias for react scaffolding

<<:  Detailed steps for smooth transition from MySQL to MariaDB

>>:  Detailed explanation of the practice of installing the Permeate range system using VMware

Recommend

mysql5.6.8 source code installation process

Kernel: [root@opop ~]# cat /etc/centos-release Ce...

MySQL learning to create and operate databases and table DDL for beginners

Table of contents 1. Operate the database 1.1 Cre...

Detailed explanation of Vuex environment

Table of contents Build Vuex environment Summariz...

Example code for text origami effect using CSS3

Preface This article mainly shares with you an ex...

Docker private warehouse harbor construction process

1. Preparation 1.1 harbor download harbor downloa...

Example of how to install kong gateway in docker

1. Create a Docker network docker network create ...

Realization of real-time file synchronization between Linux servers

Usage scenarios For existing servers A and B, if ...

JS implements simple calendar effect

This article shares the specific code of JS to ac...

MySQL trigger trigger add, delete, modify and query operation example

This article uses examples to describe the add, d...

MySQL 5.7.19 installation and configuration method graphic tutorial (win10)

Detailed tutorial on downloading and installing M...

Tutorial on installing mysql5.7.18 on mac os10.12

I searched the entire web and found all kinds of ...

XHTML introductory tutorial: Web page Head and DTD

Although head and DTD will not be displayed on th...

Uniapp implements DingTalk scan code login sample code

Since Uniapp does not have DingTalk authorization...