我想知道如何使用 expo 管理环境。
我尝试按照这篇文章进行操作,但在检测模式下出现错误。
我替换了'expo'中的导入常量;通过从'expo-constants'导入常量;。
环境.js
/*****************************
* environment.js
* path: '/environment.js' (root of your project)
******************************/
import Constants from 'expo-constants';
const ENV = {
dev: {
apiUrl: 'http://localhost.com/api',
},
staging: {
apiUrl: "https://website.com/api",
},
prod: {
apiUrl: "https://website.com/api",
}
};
const getEnvVars = (env = Constants.manifest.releaseChannel) => {
// What is __DEV__ ?
// This variable is set to true when react-native is running in Dev mode.
// __DEV__ is true when run locally, but false when published.
if (__DEV__) {
return ENV.dev;
} else if (env === 'staging') {
return ENV.staging;
} else if (env === 'prod') {
return ENV.prod;
}
};
export default getEnvVars;
当我打开“生产模式”时,我有这个错误:
undefined 不是对象(评估'j.websiteUrl')
如果可以检查模式,我认为我的错误将得到修复。