For the project of creat-react-app scaffolding, how to automatically match the backend request interface address when packing according to the different production environment and development environment?

Select the development interface address according to npm start,
npm run build select the production environment address

Jul.04,2022

1.start and build start different webpack configuration files
2. Define some environment variables in different webpack configuration files, using webpack define plugin
3. Distinguish url


based on defined global variables in the code < H2 > package.json commands to configure the environment < / H2 >

Development environment:
"dev": "cross-env NODE_ENV=development babel-node. / server.js",

package
"build": "npm run clean & & npm run build:prod"
"build:dev": "cross-env NODE_ENV=development webpack-- colors-- config-- progress",
"build:prod": "cross-env NODE_ENV=production webpack-p-colors-progress-- optimize-minimize",

production environment:
"start": "cross-env NODE_ENV=production babel-node. / server.js",

as above, use cross-env NODE_ENV=xxxxxxx to determine the environment.

< H2 > then assign different addresses according to the environment at the location of the configured address < / H2 >

if you use axios to process the request, you can write:
axios.defaults.baseURL = process.env.NODE_ENV = = 'development'?'

creat-react-app are all ready for you
process.env.NODE_ENV = development Development Environment
process.env.NODE_ENV = production production Environment

in js code:

if(process.env.NODE_ENV = 'development'){
    console.log('')
}else if(process.env.NODE_ENV = 'production'){
    console.log('')
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bc91dd-3096e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bc91dd-3096e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?