How does webpack dev configure multiple server addresses to change the server IP port of global HTTP requests through npm run dev:a/b/c?

how to configure multiple server addresses in, webpack dev development mode?
when running different script scripts, the page request points to a different server

for example:
serverList.js configure some backend server IP and ports

/*serverList.js*/
module.exports = {
    william: {
        IP: "172.18.188.127",
        PORT: "8080",
    },
    justin: {
        IP: "193.112.51.142",
        PORT: "8080"
    },
    louis: {
        IP: "localhost",
        PORT: "8080"
    }
}

package.json, defines the script, which server the http request points to

script: {
    //dev
    "dev": "webpack-dev-server --devtool eval --inline --progress --config build/webpack.dev.conf.js",
    //build
    "build": "node build/build.js",
    
    //
    "dev:louis": "npm run dev",// httphttp://localhost:8080/
    "dev:justin": "npm run dev",// httphttp://193.112.51.142:8080/
    "build:william": "npm run build",// httphttp://172.18.188.127:8080/
}

cross-env learn


inject environment variables, and then judge

by environment variables.
process.env.xxx

you can use the webpack definePlugin plug-in to search

for yourself.

have you solved it at last? if so, can you send out the steps to solve it? thank you

.
Menu