How to pass own environment variable to UMIJS application?

1.2k views Asked by At

I have created an application using UMIJS and is working fine. But now I want to load some environment variables to my application using the .env file or by exporting them. But none of the variables are getting passed to the application.
Also, all other libraries like dotenv, etc are not working.
Only UMIJS Defined env variables are working like PORT HOST etc.
This is very important for me to load my env variables somehow to the application. Anyone having any perfect solution for this will be a great help.

1

There are 1 answers

0
Sarthak Dwivedi On

To add env variables to ant-design-pro project go to config\config.ts or config\config.js depending on if you are using js or ts version.

Add a define key and assign it an Object in your config object,

export default defineConfig({
  .....
  define: {
    API_KEY: 'js3jhkj4n2kjnd',            
  },
});

You can then just use API_KEY in you project file, no need to import or prefix it with process.env.API_KEY.