environment variables not working #2664
-
I'm trying to set custom environment variables in packageOptions: {
env: {
SNOWPACK_PUBLIC_TEST: "yolo",
PUBLIC_API_URL: "woot"
}
}, and reference them in code, but they don't ever show up on reproduction: https://github.com/geddski/snowpack-env-vars Anyone know what's up? Snowpack bug, or am I doing it wrong? Edit: snowpack v |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Good question: refer to this documentation: https://www.snowpack.dev/reference/environment-variables Snowpack grabs env variables directly from your
Re-reading the docs, I can see how this could be more clear! Would love anyone to add a PR to clarify that page of the docs |
Beta Was this translation helpful? Give feedback.
-
Tried 2nd option, it's too complicated, I don't have a clue how to read variables in single-page plain Svelte app I'm building, tried some things but it seems so complicated. Trying now with plugin-dotenv, but still I don't have a clue how to actually read the content of .env files, is there any help out there, some tutorial about it, I haven't been able to find any? |
Beta Was this translation helpful? Give feedback.
-
It's so weird! First off, thanks @FredKSchott and @geddski . I used the reproduction repo to figure it out. What I noticed: when you try in a svelte project (in a JS file) to So:
becomes
Turns out this |
Beta Was this translation helpful? Give feedback.
Good question: refer to this documentation: https://www.snowpack.dev/reference/environment-variables
Snowpack grabs env variables directly from your
process.env
. There are a few ways to add them to your app:SNOWPACK_PUBLIC_TEST=yolo snowpack dev
process.env.SNOWPACK_PUBLIC_TEST = 'yolo'; // ... rest of your config file
.env
file: https://www.npmjs.com/package/@snowpack/plugin-dotenvRe-reading the docs, I can see how this could be more clear! Would love anyone to add a PR to clarify that page of the docs