Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.env variables missing from build #37

Closed
stefnotch opened this issue Jul 20, 2022 · 4 comments
Closed

.env variables missing from build #37

stefnotch opened this issue Jul 20, 2022 · 4 comments

Comments

@stefnotch
Copy link

Steps to reproduce

  1. Create a .env file with VITE_CAT=meow
  2. Go to electron/main.index.ts and add console.log(import.meta.env.VITE_CAT);
  3. Run npm run dev and look at the output in the terminal.

Bug
It will say undefined

Expected
It should say meow

The issue is here, this line should probably be deleted

@caoxiemeihao
Copy link
Member

caoxiemeihao commented Jul 21, 2022

Thanks for your feedback.

For the Electron-Main process, it's more like Node.js. So we don't have to use the Vite-specifice import.meta.env. Using process.env is mor natural.

At present, Vite cann't be handled process.env.XXX. May be supported in the near future.
vitejs/vite#8843

@stefnotch
Copy link
Author

True, being able to use process.env. environment variables in the main-process would be much neater.

Any idea how I should work around process.env.VITE_CAT or import.meta.env.VITE_CAT not working at all? Especially for a build, I'd like to have them replaced with the contents of the .env file.

Currently I'm using such .env variables to set the URL of a server that the Electron app needs. Should I just hardcode the URL for now?

@stefnotch
Copy link
Author

I found a workaround that I'll try using https://github.com/ElMassimo/vite-plugin-environment#inside-the-box-

@caoxiemeihao
Copy link
Member

Support envFile options #46

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants