Fork me on GitHub
#shadow-cljs
<
2024-06-11
>
defa16:06:00

Is there an equivalent to .env and .env.local (like https://vitejs.dev/guide/env-and-mode) in shadow-cljs? I's like to have a local file, that is ignored by git to overwrite some basic configs (in git)?

thheller16:06:10

there is not. I generally do not recommend using env vars in the first place.

defa18:06:13

It is not the environment variables in particular... for example api access keys, you don't want to check these in. Something like --config-merge from a file that is ignored by version control.

thheller19:06:17

they shouldn't be in the build period. not by any means.

defa19:06:05

You‘re probably right to not have an easy mechanism build in that cause people to put secrets where they do not belong. However have some configurations you can overwrite with a local file (not version controlled) often comes in handy. In that regard the api access key was a bad example and your‘re right that it is better to avoid them by any means in the build process because otherwise they most likely leak somehow.

thheller19:06:33

in what context do you need the api key? is it a node targetted build?

thheller19:06:43

I'm not against env vars in general. I'm against using env vars that turn into compile time constants. I think that is the wrong approach the handle them.

thheller19:06:02

I'm not debating whether a .env.local file is useful. it absolutely is. just not to "insert" a build time constant.

thheller19:06:56

e.g. if its a node targetted build you should access them as actual env vars AT RUNTIME. not build time. so just js/process.env.API_KEY

thheller19:06:16

if its a browser targetted build IMHO the html should supply runtime config. and fwiw if its browser, then its public anyway so might as well be in the git repo

defa19:06:43

It’s currently targeting the browser so it has to be a bound at build time (closure define). The current approach/design (prototype for internal use only) is bad because the api key ends up in the deployed js files.

thheller19:06:43

so, the way I handle this is putting things like API keys and other config params into the HTML

thheller19:06:16

then they are effectively "environment variables" like they are supposed to be

thheller19:06:56

but all that being said .. if you like env vars and want to stick with them you can via dotenv-cli above

defa19:06:19

Thank you very much for your feedback. In guess I will use —config-merge for now until there is a proper back-end and client auth.

lilactown21:06:35

how do I import static files at build time? I remember there being a way to do this but can't seem to find the right keywords to google / search slack for

lilactown21:06:33

e.g.

(def prompt (shadow-import "prompt.txt"))
will emit the contents of "prompt.txt" at build time and will trigger the build when it changes

❤️ 1