菜鸟问题,我很抱歉.
我想知道是否有人知道 NextJS 自托管(例如 docker 或 kubernetes)的推荐部署流程.我只进行一次典型的构建,根据环境发布,同时更改环境变量以匹配环境,但保持图像相同.
I'm wondering if anyone knows the recommended deployment flow for NextJS self-hosted (e.g. docker or kubernetes). I'm doing a typical build once, ship per environment while changing environment variables to match the environment but keeping the image the same.
由于 NextJS 在您使用getInitialProps"时自动退出 SSG;和publicRuntimeConfig",我想知道,将同一映像部署到多个环境的最佳方式是什么(同样,自托管在通用云上,例如 docker run).
Since NextJS auto-opts-out of SSG when you use "getInitialProps" and "publicRuntimeConfig", I'm wondering, what's the best way to deploy the same image to multiple environments (again, self hosted on generic cloud e.g. docker run).
感谢您的帮助!
推荐答案你可能想看看 react-env 就是这样做的.
You might want to check out react-env which does just that.
这个想法是 react-env 将为您生成一个带有环境变量的 __ENV.js JS 文件,然后您可以通过窗口或通过 env 在客户端访问该文件 助手,例如:
The idea is that react-env will generate for you an __ENV.js JS file with your environment variables, which you can then access on client side via the window or via the env helper, eg:
<small> Works in the browser: <b>{env("CRA")}</b>. </small>使用 Docker 时,您可以设置入口点在容器启动时生成所需的 __ENV.js:
When using Docker, you may set an entrypoint that generates the required __ENV.js when the container boots:
ENTRYPOINT yarn react-env --env APP_ENV更多推荐
NextJS
发布评论