Skip to content

Instantly share code, notes, and snippets.

@kkirby
Created September 18, 2019 18:30
Show Gist options
  • Save kkirby/b409545dc2b9e64ad617c1f75073a416 to your computer and use it in GitHub Desktop.
Save kkirby/b409545dc2b9e64ad617c1f75073a416 to your computer and use it in GitHub Desktop.
import clients from './clients';
/**
* Start command:
* env REACT_NATIVE_APP_CLIENT=ge react-native start
* Bundle Command
* react-native bundle --reset-cache --bundle-output ./output.js --entry-file ./index.js
**/
console.log(
clients(
PROCESS_ENV.REACT_NATIVE_APP_CLIENT
)
);
/**
* if REACT_NATIVE_APP_CLIENT == ge then console.log will output { clientName: 'ge' }
* if REACT_NATIVE_APP_CLIENT == visa then console.log will output { clientName: 'visa' }
**/
import clients from './clientsdir/**/*';
export default function(client){
return clients[client];
}
export default {
clientName: 'ge'
};
export default {
clientName: 'visa'
};
@kkirby
Copy link
Author

kkirby commented Sep 18, 2019

In the filename, underscores are actually directory separators.

This uses two bable plugins:

  • The first plugin assigns PROCESS_ENV to environment variables that are passed to react-native, filtering out anything that doesn't start with REACT_NATIVE_APP.
  • The second babel plugin will allow importing multiple files at once.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment