kit icon indicating copy to clipboard operation
kit copied to clipboard

More options to indicate public environment variable then simple publicPrefix

Open xmlking opened this issue 1 year ago • 3 comments

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

xmlking avatar Jun 20 '24 03:06 xmlking

What if the prefix could accept an array so that you could specify both PUBLIC and NHOST?

benmccann avatar Jun 21 '24 12:06 benmccann

What if the prefix could accept an array so that you could specify both PUBLIC and NHOST?

Yes that could solve my needs

xmlking avatar Jun 21 '24 20:06 xmlking

I also need the publicPrefix option to be an array, just like in vite.

ivands avatar May 19 '25 18:05 ivands

Any timeline for when this issue will be picked up?

ivands avatar Sep 25 '25 18:09 ivands

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.

ivands avatar Nov 18 '25 16:11 ivands

Could we please prioritise this?

dhairya0904 avatar Nov 19 '25 09:11 dhairya0904

Please prioritize this. Allowing publicPrefix: string[] is a tiny change with a huge impact.

XDevRabi avatar Nov 19 '25 14:11 XDevRabi

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

ivands avatar Nov 19 '25 17:11 ivands