The react version when writing this article is 16.13.1 1 Enter the command npm run eject to generate a config directory in the project root directory 2 Open the webpack.config.js file under confilg and find the following location alias: { // Support React Native Web // https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/ 'react-native': 'react-native-web', // Allows for better profiling with ReactDevTools ...(isEnvProductionProfile && { 'react-dom$': 'react-dom/profiling', 'scheduler/tracing': 'scheduler/tracing-profiling', }), ...(modules.webpackAliases || {}), }, 3 Modify as follows, then restart the project alias: { // Support React Native Web // https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/ 'react-native': 'react-native-web', // Allows for better profiling with ReactDevTools ...(isEnvProductionProfile && { 'react-dom$': 'react-dom/profiling', 'scheduler/tracing': 'scheduler/tracing-profiling', }), ...(modules.webpackAliases || {}), // File path alias '@': path.resolve(__dirname, '../src'), '@view': path.resolve(__dirname, '../src/view'), }, Configure the proxy: Simple version configuration: Add directly in package.json: "proxy": "http://localhost:4000" Full version configuration: const proxy = require('http-proxy-middleware') module.exports = function(app) { app.use( proxy.createProxyMiddleware('/api', { //Requests with api need to be forwarded target: 'http://localhost:4000', // This is the server address changeOrigin: true, //The value is a Boolean value. When it is true, a virtual server will be created locally to receive your request and send the request on your behalf. pathRewrite: {'^/api': ''} }) ) } 3. Note: After the react scaffolding is configured with a proxy, the front-end resources will be requested first when requesting resources. If there are no resources, the back-end resources will be requested. This is the end of this article about how to configure path aliases for react scaffolding. For more information about how to configure path aliases for react scaffolding, please search 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:
|
<<: Working principle and example analysis of Linux NFS mechanism
>>: In-depth analysis of Linux NFS mechanism through cases
I remember that a few years ago, there was an int...
This article example shares the specific code of ...
border-radius: CSS3 rounded corners Syntax: borde...
MySQL Query Cache is on by default. To some exten...
Table of contents Preface No.1 A focus No.2 Extra...
Table of contents Parsers and preprocessors Query...
Preface: Last Sunday, a senior asked me to help m...
Background Controller @RequestMapping("/getP...
1. px px is the abbreviation of pixel, a relative...
MySQL is an open source small relational database...
There are two ways to create a primary key: creat...
This article shares the specific code for WeChat ...
Table of contents 1. Shallow cloning 2. Deep clon...
1 Introduction When we write SQL statements to op...
Introduction to Git Git is an open source version...