Build once, deploy everywhere
Answered
Polar bear posted this in #help-forum
Polar bearOP
I am trying to fix our build pipeline and get to the "build once, deploy everywhere" nirvana (see links below for the in-depth explanation of "why").
However, I am not a Next.js expert, so pardon if the questions are too simplistic or silly. I am a reasonably experienced developer with a strong background in both React and build systems, but I am not as familiar with Next.js.
What I am trying to understand is if this is feasible in the Next.js land. Has anyone been able to achieve this?
Essentially, the simple mental model is that I don't want any
I've done similar things with pure React and Remix. But don't understand how to achieve this with Next.js.
Resources:
- https://blog.innei.ren/nextjs-runtime-env-and-build-once-deploy-many
- https://profinit.eu/en/blog/build-once-deploy-many-in-react-dynamic-configuration-properties/
- https://www.redhat.com/en/blog/build-once-deploy-anywhere
Thanks!
However, I am not a Next.js expert, so pardon if the questions are too simplistic or silly. I am a reasonably experienced developer with a strong background in both React and build systems, but I am not as familiar with Next.js.
What I am trying to understand is if this is feasible in the Next.js land. Has anyone been able to achieve this?
Essentially, the simple mental model is that I don't want any
NEXT_PUBLIC_*
environment variables at all. All external values should be provided via runtime envs and bubbled up to the frontend (this is the main unknown to me).I've done similar things with pure React and Remix. But don't understand how to achieve this with Next.js.
Resources:
- https://blog.innei.ren/nextjs-runtime-env-and-build-once-deploy-many
- https://profinit.eu/en/blog/build-once-deploy-many-in-react-dynamic-configuration-properties/
- https://www.redhat.com/en/blog/build-once-deploy-anywhere
Thanks!
Answered by Asian black bear
12 Replies
Asian black bear
Answer
Asian black bear
You can even combine it with https://env.t3.gg which is pretty nice.
Polar bearOP
@Asian black bear yeah, that's the one mentioned in the article I linked. But GH repo seems to be full of issues and edge cases. Doesn't sounds like a solid solution. I was looking for something robust. Can it really be that difficult to pass runtime envs?
Asian black bear
I have been using this for a while and haven't experienced any issues.
Even more irritating is that people claim that standalone mode isn't supported and I am using it just fine. Chances are they have an incorrect setup 🤷♂️
Polar bearOP
How do you use it with t3 env?
Asian black bear
Polar bearOP
So there should be nothing under the client and server then as all of the values are runtime?
Asian black bear
Incorrect, you split them regardless.
What changes is that you just provide all environment variables within the runtime section, both public and private ones.
Polar bearOP
So you define all envs twice then? Split by server client and then once more both servers and client into runtime?
Asian black bear
You have to do that anyways, since the server and client properties in the snippet are just the schema.