Webpack 网页包动态url api

Webpack 网页包动态url api,webpack,Webpack,我的网页包和api url有一些问题。 我与Jenkins建立了一个关系,Jenkins将我的应用部署在两台服务器上 我有两个后端url(与前端url相同): Recette:12.122.125.208 产品编号:12.122.125.209 我的网页包配置: build: { env: require('./prod.env'), index: path.resolve(__dirname, '../dist/index.html'), assetsRoot: p

我的网页包和api url有一些问题。 我与Jenkins建立了一个关系,Jenkins将我的应用部署在两台服务器上

我有两个后端url(与前端url相同):

  • Recette:12.122.125.208
  • 产品编号:12.122.125.209
我的网页包配置:

build: {
    env: require('./prod.env'),
    index: path.resolve(__dirname, '../dist/index.html'),
    assetsRoot: path.resolve(__dirname, '../dist'),
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',
    productionSourceMap: true,
    productionGzip: false,
    productionGzipExtensions: ['js', 'css'],
    bundleAnalyzerReport: process.env.npm_config_report
  },
我的prod.env文件:

module.exports = {
  NODE_ENV: '"production"',
  URL_API: '"http://12.122.125.208/api/"',
};
可以基于当前URL创建动态URL,例如:

const = BASE_URL;
URL_API: BASE_URL + '/api/"',
这样,我就可以为我的两台服务器部署一次

我该怎么做


谢谢。

您可以配置多个“Jenkins”,并具有不同的配置文件:

  • 部署到“接收器”:
    BASE\u URL=12.122.125.208
  • 部署到“Prod”:
    BASE\u URL=12.122.125.209
然后使用
process.env.BASE\u URL
从您的网页配置访问此
BASE\u URL