ReactNative (Expo) 環境変数
expoには release channel という機能があり、publish時--release-channelを指定することでファイル内で code:js
import { Constants } from 'expo';
console.log(Constants.manifest.releaseChannel);
このようにしてその値を取得することができる
これを利用して環境変数をchannelで出し分ける
code:env.js
import { Constants } from 'expo';
const ENVs = {
development: {
environment: "dev",
},
staging: {
environment: "staging",
},
production: {
environment: "production",
},
};
export default () => {
switch (Constants.manifest.releaseChannel) {
case 'staging':
return ENVs.staging;
case 'production':
return ENVs.production;
default:
return ENVs.development;
}
};
ref