I'm trying to add environment variables to a Svelte project. Tryied lots of solutions, including this but all I get is the error "Uncaught ReferenceError: __myapp is not defined"
1 Answer
The article appears to be outdated, the replace function has to contain something like this. Check the readme for plugin replace.
add this to the rollup.config.js
replace({
values: {
__myapp: JSON.stringify({
isProd: production,
...config().parsed
}),
},
}),
App.svelte file.
<script>
console.log(__myapp);
const { isProd, API_URL } = __myapp;
</script>
<h4>{isProd} - {API_URL}</h4>