React 配置全局变量

React 配置全局变量

使用webpack,您可以将env特定的配置放在webpack.config.js中的externals字段中

externals: {
  'Config': JSON.stringify(process.env.ENV === 'production' ? {
    serverUrl: "https://myserver.com"
  } : {
    serverUrl: "http://localhost:8090"
  })
}

然后在你的模块中,你可以使用config:

var Config = require(‘Config’)
fetchData(Config.serverUrl + ‘/Enterprises/…’)

你可能感兴趣的:(React 配置全局变量)