hackgvl / hackgreenville-com

HackGreenville's Website
https://hackgreenville.com
MIT License
16 stars 15 forks source link

Make Vite config a bit more flexible #234

Closed JSn1nj4 closed 1 month ago

JSn1nj4 commented 2 months ago

This is more minor since it's a DX thing, but I wanted to ask if I could make some of the Vite settings more configurable while keeping the current defaults.

Right now, these options are set either explicitly or implicitly:

server.host = '0.0.0.0'
server.https = false
server.hmr.host = '0.0.0.0'

This works if you run projects with the default options, including plain HTTP. But I like dev w/ HTTPS, so I'd like the option to turn that on. It forces the browser to error in case any resources are loaded over plain HTTP.

We can have a few small functions in the Vite config that check for .env vars and otherwise set the defaults.

Does this sound alright? (@ThorntonMatthewD @bogdankharchenko)

zach2825 commented 1 month ago

Updating all configs to be more dynamic will always be preferable. Since we hope to have many people contributing to the project, we want to make it easy for them to start.

I've added a rough example of the idea. If you destruct process.env and set the constants you need in the file to defaults, people can easily override the defaults in their own .env file.

1) process.env parses the .env file 2) example of defaulting the server URL to the computer's loopback 0.0.0.0

image

JSn1nj4 commented 1 month ago

Neat, that's even simpler than what I was going to do. Didn't realize you could set defaults when destructuring an object.