your question is fair. Dev and Build are total different beasts, Astro is using Vite, you can read Vite doc if you want to know the difference. As of why eval is a security risk, is that if connected to user input users can hack your site, you might say but you didn't connect it to user input, the compiler prefers to be on the safe side, rather safe than sorry.
#eval() difference dev/build in client
1 messages · Page 1 of 1 (latest)
this isn't answering the question but it might be helpful (to avoid eval)
if in someDumbData you export default an object of those consts, like:
const tree_oak = "oak tree";
const tree_spruce = "spruce tree"; // or whatever your data is
export default { tree_oak, tree_spruce }
then you can
import trees from "./someDumbData";
function myFunction() {
let theTree = "oak";
alert(trees[`tree_${theTree}`]);
}
this code would only work for you if tree_oak and tree_spruce are the only data in someDumbData in which case you could rename it to trees.js/trees.ts
so is there any way to configure vite to make eval work? Can't really find things about configuring vite in astro
Here a link in Astro doc how you can configure Vite in Astro https://docs.astro.build/en/reference/configuration-reference/#vite
And this is for Rollup, might be more relevant for you for eval https://docs.astro.build/en/guides/configuring-astro/#customising-output-filenames
How whould this be useful for making eval work? Im trying different vite options for a while now but can;t get it.
Oh, that shows how to customize "rollupOptions" and when I searched about eval config in Vite, it involved those "rollupOptions". That's only a lead, I do not know the solution.
I can find nothing specific about eval in the Vite docs