Our great sponsors
-
SurveyJS
Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App. With SurveyJS form UI libraries, you can build and style forms in a fully-integrated drag & drop form builder, render them in your JS app, and store form submission data in any backend, inc. PHP, ASP.NET Core, and Node.js.
-
envsafe
🔒 Makes sure you don't accidentally deploy apps with missing or invalid environment variables.
-
WorkOS
The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.
This is what cra-envs does.
But NextJS does statically build. Sure server side code would be dynamic but not any client side static content. I've found https://github.com/vercel/next.js/tree/canary/examples/with-docker-multi-env now which is new but its not a great solution either.
But... we don't control the environment where it is deployed! We ship an open source application called 0nyxia. Our users deploy it themselves. We can't tell them to clone and build. Beside even if we had full control. It's a waste of resources to rebuild the whole application when it's possible to just restart with different environment variables.
In next JS it's much easier. It's not static, node can read the environment variables. For validation and type safety, you can use this.
This package does the same for Next.js. It's actually a very simple concept that can be done without the package tbh. We use an older version at my work and there's a few challenges (ie11 support which thank God is becoming less of an issue) also the package ingests the env vars in a different order than Next.js which can be a trip at first. The second complaint can be solved by a home grown solution lol.
Related posts
- Next.js with Public Environment Variables in Docker
- Runtime variables vs build time variables in ReactJS
- Docker build per environment vs. single build for all environments
- Bundle environment variables in create-react-app at launch time (not build time)!
- Bundle environment variables in create-react-app at launch time (not build time)!