Runtime Env vars in vite
Hey all, I'm trying to figure out a way to run environment variables at runtime rather than at compile time. I've been looking at https://iendeavor.github.io/import-meta-env/ , but I can't seem to get it to work. Specifically, in
transformMode: "runtime"
, trying to use this code in a script called by index.html (in fact, a script tag in index.html) just makes global.import_meta_env to be the placeholder, it doesn't get replaced.
I need this because our build system builds once and then distributes to other servers for various regions. We also have staging/beta/dev servers built the same way.
Anything I'm missing? (This isn't necessarily related to solidjs, but, it's a thing that could be used with solidjs 😉 )Import-meta-env | Startup/Runtime environment variables solution fo...
Build once, deploy anywhere. Import-meta-env helps to developing applications following the 12-factor principles.
5 Replies
just use nodes
process.env
?at runtime after build? don't think you understood the question.
dammit. Turns out, I was missing the last step - you need to inject the vars, and that requires a script... or a dockerfile that calls an sh script that does the replacement. which we already had. smh.
https://stackblitz.com/edit/solidjs-templates-qxvqnt
haha, yeah
TIL about the plugin, thanks, pretty useful
yep! that's the one 😄
I'm an absolute donkey, lol 😄
the docs could definitely be improved, it isn't that clear what you have to do exactly