Use .env files with your Svelte project

18 · Samuel El-Borai · Nov. 11, 2020, 4:28 p.m.
I recently learned a nice way to manage your .env files in your Svelte projects. If you're using Rollup as your bundling tool, which is likely to be the case, you can use the node module dotenv to automatically inject the content of a .env file into your web page. Install dotenv via npm install dotenv At the top of your rollup.config.js, import and load the environment variables: import dotenv from "dotenv" dotenv.config() // inject the content of the .env file into 'process.env' Then, in t...