NextJS - Deployment
Build Once, Deploy Anywhere
- Is a key software engineering principle
- So we use Docker to package application, so that it's environment agnostic.
- However NextJS Static Export does not support this principle
NextJS Static Export
- In NextJS, env variables are evaluated and interpolated at build time.
- If you want to change the value for different stage, you need to rebuild the app and create separate docker images.
- Not possible to inject different env configurations in different environment
- End up have to build the artifacts multiple times for each environment
- The "build once, deploy anywhere" philosophy is at odds with having statically generated pages and content built into the image.
- There is no way to access runtime environment variables in static pages.
- This is because static pages are pre-rendered at build time.
- Ideally we can create a single Docker image and resuse them across multiple environments