Capítulo 401 de 456

generateBuildId

Core Idea

Controls the build ID Next.js generates during next build to identify the version of your app being served, useful when the same build must run across multiple containers.

Key Concepts

  • generateBuildId: async/sync function in next.config.js that returns a custom string used as the build ID instead of the default random one.
  • deploymentId: when set, overrides this option entirely, Next.js uses a constant build ID and generateBuildId has no effect.

Code Examples

module.exports = {
  generateBuildId: async () => {
    // This could be anything, using the latest git hash
    return process.env.GIT_HASH
  },
}
  • O que demonstra: gerar um build ID consistente (hash do git) para reutilizar entre múltiplos containers no mesmo deploy.

Key Takeaways

  1. Use quando fizer rebuild por estágio de ambiente e precisar do mesmo ID entre containers.
  2. Se deploymentId estiver configurado, este campo é ignorado, version skew passa a ser detectado pelo deployment ID.

Connects To

  • deploymentId: substitui o comportamento de generateBuildId quando definido.
  • Self-hosting / version skew: contexto de uso desse ID em produção multi-container.