saltyshiomix / nextron

⚡ Next.js + Electron ⚡
https://npm.im/nextron
MIT License
3.97k stars 229 forks source link

Handling environment/configuration variables #128

Open dac09 opened 4 years ago

dac09 commented 4 years ago

Hi!

First, thank you so much for putting this together!

I had a question, regarding environment (or configuration) values. Do you have recommendations on how to configure the build with different configuration values e.g. api endpoint?

Right now I can see that we can use .env files inside renderer, but there's no obvious way of using environment variables in the main process (as macos doesn't load env variables when you launch outside the command line).

Perhaps something like this can be used when compiling the main code https://www.npmjs.com/package/babel-plugin-transform-inline-environment-variables?

Thanks in advance!

dac09 commented 4 years ago

As an aside, I think what would be really helpful is if we could customise the webpack configuration i.e. add our own plugins, and nextron can merge the configs.

jt-l commented 10 months ago

Any further insight on this? How to incorperate .env into nextron build? Do we have to use webpack (i.e., next.config.js)?

jt-l commented 10 months ago

Any further insight on this? How to incorperate .env into nextron build? Do we have to use webpack (i.e., next.config.js)?

I resolved the issue, nextJS will automatically pick up variables defined in .env.local in renderer, but they need to be prefixed with NEXT_PUBLIC in order to use them on the client side.