javascriptreactjsreact-nativedeveloper-tools

Set up custom developer options in React Native


Is it possible to add custom developer options to your React Native app? For instance I would like to add the possibility to change the endpoint to which the app connects so I can switch between localhost, staging, production etc. on my mobile phone


Solution

  • With webpack you can use proccess.environment plugin, so you will be able to use

    if (process.env.NODE_ENV === 'dev')  {
      makeYourThingIncludingRequereETC();
    }
    

    https://github.com/webpack/docs/wiki/list-of-plugins#environmentplugin

    it will be transpiled to if ('prod' === 'dev') {} in prod environment before build and minification, which will be removed from code due to 'always false' rule.