Manage environment with expo react native

有些话、适合烂在心里 提交于 2020-05-30 08:46:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!