When judging the environment in webpack.config.js, use the function to export,
"scripts": {
"serve": "webpack-dev-server --mode development --progress --open",
"build": "webpack --env.production --mode production --progress"
},
module.exports = function (env, argv) {
console.log(env, argv);
}
–mode
Used to specify which mode to use, there are three types of production, development, and none. If production is used, some optimizations will be made to the formal environment, such as removing map files, adding code compression, etc., if it is development, it will have the function of opening some development environments. . For local development, webpack-dev-server will use development mode for startup, and production mode for packaging and uploading online.
–env.xxxx
Specify which environment to use, such as development environment, test environment, and formal environment. These three environments will have corresponding API request addresses. You can use this method to determine which API to use in different environments