I try to run different env files with different environment variables with expo react native web.
And I am using expo react native web. So not react-native and not reactjs. I cannot find the configuration for expo react-native-web
So I have two different env files:
dev and prod
.env file looks like:
GENERATE_SOURCEMAP=false
REACT_APP_NAME=dierenwelzijn_dev
and .env.production looks like:
REACT_APP_ENV=PRODUCTION
REACT_APP_API_URL=https://dierenwelzijndocker.azurewebsites.net
And I installed the package: env-cmd
Part of package.json file looks:
"scripts": {
"start:prod": "env-cmd -f .env.production expo start --openssl-legacy-provider, react-app-rewired start react-scripts start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"eject": "expo eject",
"lint": "eslint . --ext .js",
"postinstall": "patch-package",
"build": "react-scripts build",
"start-webpack": "webpack-dev-server --mode production --open"
},
"dependencies": {
"@ant-design/icons": "4.0.0",
"@expo-google-fonts/lato": "^0.2.2",
"@expo-google-fonts/oswald": "^0.2.2",
"@expo/config": "^8.1.2",
"@expo/webpack-config": "^18.1.3",
"@react-native-async-storage/async-storage": "~1.15.0",
"@react-navigation/bottom-tabs": "^6.5.4",
"@react-navigation/native": "^6.1.3",
"@react-navigation/stack": "^6.3.14",
"babel-plugin-styled-components-react-native-web": "^0.2.2",
"css-to-react-native": "^3.2.0",
"env-cmd": "^10.1.0",
"expo": "^49.0.21",
"expo-font": "~10.0.4",
"expo-screen-orientation": "^6.2.0",
"expo-status-bar": "~1.2.0",
"lottie-react-native": "5.0.1",
"next-transpile-modules": "^10.0.1",
"patch-package": "^8.0.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-native": "0.72.6",
"react-native-gesture-handler": "~2.1.0",
"react-native-paper": "^5.1.3",
"react-native-safe-area-context": "3.3.2",
"react-native-screens": "~3.10.1",
"react-native-svg": "^12.5.1",
"react-native-web": "~0.19.6",
"react-native-web-lottie": "^1.4.4",
"react-toast-notifier": "^1.0.3",
"styled-components": "^5.3.6",
"webpack-cli": "^5.1.4"
},
and one of my api calls looks:
export const loginRequest = async (email, password) => {
try {
const response = await fetch("http://127.0.0.1/api/user/token/", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
email: email,
password: password,
}),
});
const data = await response.json();
if (response.ok) {
await AsyncStorage.setItem("Token", data.token);
return true;
} else {
throw new Error(data.token);
}
} catch (error) {
error, "email en of wachtwoord is niet goed ingevuld";
}
};
I start the react native web app with the command:
expo start
and then I choose for option w-for web. And the app is running on port:
http://localhost:19006/
Queston: how can I now use the environment file for production?