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/…’)