问题
I would like to know how can I manage environment with expo.
I tried to follow this article, but I have an error, on detect mode.
I replaced import Constants from 'expo'; by import Constants from 'expo-constants';.
environment.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;
When I turn on "production mode", I have this error :
undefined is not an object (evaluating'j.websiteUrl')
If I can to check the mode, I think that my bug will be fixed.
来源:https://stackoverflow.com/questions/57494552/manage-environment-with-expo-react-native