SolidJSS
SolidJSโ€ข3y agoโ€ข
10 replies
Alterion

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.
   <script>
     globalThis.import_meta_env = JSON.parse('"import_meta_env_placeholder"');
     console.log(import_meta_env); // import_meta_env_placeholder
   </script>


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 ๐Ÿ˜‰ )
Build once, deploy anywhere. Import-meta-env helps to developing applications following the 12-factor principles.
Was this page helpful?