W
Wasp-lang•5w ago
josh

Do I need to add client side env variable every time I deploy?

Do I need to add in my client side env variables every time I deploy like so? REACT_APP_GOOGLE_ANALYTICS_ID=example wasp deploy fly deploy, or just for the first time? If every time, is there a way around that?
6 Replies
MEE6
MEE6•5w ago
Wohooo @josh, you just became a Waspeteer level 2!
kapa.ai
kapa.ai•5w ago
Hi @josh. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Yes, you would need to add the client-side environment variable every time you deploy using the wasp deploy fly deploy command. This is because the environment variable is embedded into the client code during the build process, and this value needs to be provided each time you build and deploy your application. Here is how you would do it:
REACT_APP_GOOGLE_ANALYTICS_ID=example wasp deploy fly deploy
REACT_APP_GOOGLE_ANALYTICS_ID=example wasp deploy fly deploy
However, for development purposes, Wasp allows you to define environment variables in a .env.client file in the root of your Wasp project. Variables defined in this file will be provided to the client during development. This file should not be committed to version control, and it is already ignored by default in the .gitignore file that comes with Wasp. Here is an example of how you would define a client-side environment variable in the .env.client file:
REACT_APP_GOOGLE_ANALYTICS_ID=example
REACT_APP_GOOGLE_ANALYTICS_ID=example
Please note that this method is recommended for development and not for production. For production, you should provide the environment variables to the build command as shown in the first example. For more information, you can refer to the Wasp documentation on environment variables (https://wasp-lang.dev/docs/project/env-vars). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @josh, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
miho
miho•5w ago
@sodic one for you, I think a nice bash script could help
Filip
Filip•5w ago
Ah, so I'm the script guy. Can't complain 🙂 @josh Like miho said, if you're tired of typing it out, you can create a bash script with the command and place it into your folder:
#!/bin/bash
REACT_APP_GOOGLE_ANALYTICS_ID=example wasp deploy fly deploy
#!/bin/bash
REACT_APP_GOOGLE_ANALYTICS_ID=example wasp deploy fly deploy
Let's say you save it under the name deploy. You can then run the command by doing source deploy Btw, I personally probably wouldn't create a script and would instead use the shell's reverse backup feature: Press Ctrl + R on the command line and start typing. The shell will search the history for the command you need, and just press enter
martinsos
martinsos•4w ago
Although script is nice if you have multiple team members + terminal history can get wiped out in some cases, so I would personally go with a script 💯
Filip
Filip•4w ago
Just make sure not to commit the script if it contains something sensitive (probably not since it's the client's env vars, but you never know)
Want results from more Discord servers?
Add your server