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
This is the content of React 16. It is not the la...
Preface Recently, due to work needs, I need to in...
Detailed example of IOS database upgrade data mig...
MySQL Create Database After logging into the MySQ...
Login + sessionStorage Effect display After a suc...
Docker is an open source engine that makes it eas...
Table of contents EffectList Collection EffectLis...
Content Detail Tags: <h1>~<h6>Title T...
Table of contents Introduction to FTP, FTPS and S...
The paging effect is implemented in the vue proje...
Disadvantages of single-node database Large-scale...
Use the mysql command to connect to the MySQL ser...
When developing and debugging a web application, ...
1. Stop the database server first service mysqld ...
Preface When developing WeChat applets, you often...