react项目开发环境和生产环境baseURL的配置

381 阅读1分钟

一、手动写

export const BASE_URL = 'http://hyy.dev:9002'
export const BASE_URL = 'http://hyy.pro:9002'

二、根据process判定

let BASE_URL = ''
if (process.env.NODE_ENV === "development") {
  BASE_URL = 'http://hyy.dev:9002'
} else {
  BASE_URL = 'http://hyy.pro:9002'
}

三、增加.env.development和.env.production文件

//.env.development
REACT_APP_BASE_URL = http://hyy.dev:9002
//.env.production
REACT_APP_BASE_URL = http://hyy.pro:9002