-
Install
@snowpack/plugin-dotenv
npm i --save @snowpack/plugin-dotenv
-
Configure Astro via
astro.config.mjs
to use@snowpack/plugin-dotenv
plugins: [ "@snowpack/plugin-dotenv", ],
-
Expose Env Vars via Snowpack's
snowpack.config.mjs
. Vars must be prefixed withSNOWPACK_PUBLIC_
export default { env: { SNOWPACK_PUBLIC_API_BASEURL: 'https://myapi.example.org/', }, };
-
Access the Env Vars on the
__SNOWPACK_ENV__
objectconst res = await fetch(`${__SNOWPACK_ENV__.SNOWPACK_PUBLIC_API_BASEURL}/events`);
Created
October 17, 2021 09:13
-
-
Save bramus/093dadabcac610c58a3e133b64f97417 to your computer and use it in GitHub Desktop.
Astro Env Vars
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment