DEV Community

Discussion on: How to load dynamical environment variables with Nuxt.js

Collapse
 
kissu profile image
Konstantin BIFERT • Edited

Hi ! Does it work w/ full static generation ? I've tried basic yarn generate then FANCY_TOKEN="NICE_TOKEN" yarn start but it's empty... Could you please help ? :)

Collapse
 
mrnaif2018 profile image
MrNaif2018

Hi! Of course it doesn't work neither in SPA nor in full static
Where would it get env variables from? Client browser? 😀
It works in SSR mode only, it's whole point is to be able to change some variables server-side after build. Full static mode just generates ready html for use with static hosting. It's just html files which can't use anything from the server. Same goes for SPA

Collapse
 
kissu profile image
Konstantin BIFERT

I actually achieved it with SPA without too much trouble (publicRuntimeConfig is dope simple to use in fact). :D
But yeah, it does probably not work in full static or maybe with some hacky stuff like this one: github.com/DreaMinder/nuxt-env-inj...

And yeah, I do agree that it's probably not feasible in full static for obvious reasons but who knows, it was maybe a cool way of handling this one.

Still thanks for the quick reply and have a great day. 😃