kit
kit copied to clipboard
More options to indicate public environment variable then simple publicPrefix
Describe the problem
i like sveltekit support array for publicPrefix config. I have to deal with a vendor lib that expect public environment variables prefixed with NHOST_* and rest used PUBLIC_* . With current limitation, I have to define duplicate variables
my usecase : https://github.com/xmlking/spectacular/blob/916ef57220c6ef451dc9317e26201bb75a1641c3/.env.example#L42****
Describe the proposed solution
While using some 3rd party service provides ( CMS, Backend-as-a-Service, payment systems) with SvelteKit, we have to use vender provided libraries to interact with their system, sometime they have some Convention-over-configuration to use environment variables that are prefixed with certain text (e.g., NHOST_, VERCEL_ etc) . If those environment variables are needed on both client-side as well as server-side, we have to duplicate them once with vendor prefix and PUBLIC_which leads to duplication.
It will be nice to allow multiple patterns/prefixes to indicate public variables in SvelteKit to support such use-cases.
Alternatives considered
Inspired from Astro astro:env , methodology described here seams more flexible https://astro.build/blog/astro-4100/
Importance
nice to have
Additional Information
Ref https://x.com/xmlking/status/1803533098170327073?s=61&t=prjj5Lm6MXpnSZaenY1B-A
What if the prefix could accept an array so that you could specify both PUBLIC and NHOST?
What if the prefix could accept an array so that you could specify both
PUBLICandNHOST?
Yes that could solve my needs
I also need the publicPrefix option to be an array, just like in vite.
Any timeline for when this issue will be picked up?
This problem is quite annoying because we now have to send our env vars via a load function to the client side.
But this will make sharing code via the client side & server side super annoying.
Because svelte will complain that I can't sure page.data.env.MY_ENV on the server side.
Could we please prioritise this?
Please prioritize this. Allowing publicPrefix: string[] is a tiny change with a huge impact.
As a temp workaround, is there some place we can rename env vars and add the prefix ??? Because it doesn't work inside the hooks.server.ts file