I am trying to set the env variables in my app using https://medium.com/dev-cafe/how-to-setup-env-variables-to-your-svelte-js-app-c1579430f032
import {config} from 'dotenv';
import replace from '@rollup/plugin-replace';
plugins: [
//Environment varialbes
replace({
// stringify the object
__myapp: JSON.stringify({
env: {
isProd: production,
...config().parsed // attached the .env config
}
}),
}),
But when I try to access the env variables using "__myapp.env.API_ID", I get the following error in the dev tool - Uncaught Reference Error: __myapp is not defined"
Only way I could make it work is
import {config} from 'dotenv';
import replace from '@rollup/plugin-replace';
config()
plugins: [
//Environment varialbes
replace({
API_ID: JSON.stringify(process.env.API_ID)
}),