Environment variables

I want to add environment variables to my project, does anyone know how to do it?
I’ve read something about creating a configuration folder and using prod.json and dev.json files, but I didn’t get it. So if someone could be more precise and detailed in their solution, would be great.

This is the similar question: Variables de entorno

Hello @Pol

The topic you shared has a solution provided by Erika. Did you try that solution and it didn’t work on your end? Or was something unclear in the solution she shared?

Eduardo Luciano
Field Software Engineer | VTEX

The solution was unclear to me. I tried to follow it, but there were some steps that I didn’t know how to solve them.
Following the example, do I have to add a configuration builder? it talks about PROD.ACCOUNT but how I have to name it in prod.json? is his name ACCOUNT or PROD.ACCOUNT and in dev.json, do I name it ACCOUNT or DEV.ACCOUNT
She says that:
if(production) {mivariable = PROD.ACCOUNT} else {mivariable=DEV.ACCOUNT }?

Hi @Pol

I believe that was simply a placeholder for a response.

In the github repository Erika shared, you can see a bigger example of using the production attribute in a function:

Hi @eduardo.luciano
What I’m struggling with is the relationship between config/prod.json or config/dev.json with react/theTsFileWhereIWantToAddTheEnv.ts. So how I connect this two files?

I know that I can import a json like any React project, but I expect something different, if not, I don’t understand the necessity of useRuntime for an .env question. useRuntime is only for the ability of changing environment variables from development or from production, but if you have constant environment variables, then is not necessary.

So to conclude, if you are telling me that vtex propose to substitute .env for .json, then I’ve been wasting my time searching for a solution that I knew at the begining. And also if you are telling me that vtex gives you the oportunity to change the jsonFile if I’m in production or development then… I knew that too. :smiling_face_with_tear: