Capítulo 211 de 456
Legacy API to inline environment variables into the JS bundle at build time via next.config.js; superseded by the standard .env files approach since Next.js 9.4 — avoid for new code.
env config: object of key/value pairs; values are always inlined into the client bundle (no NEXT_PUBLIC_ prefix needed/relevant here).process.env.customKey is replaced with the literal value via webpack DefinePlugin, so destructuring process.env doesn't work.module.exports = {
env: {
customKey: 'my-value',
},
}
process.env.customKey no bundle.function Page() {
return <h1>The value of customKey is: {process.env.customKey}</h1>
}
'my-value' em build time.env config pra novos projetos: é API legada; prefira a abordagem padrão de variáveis de ambiente (.env, prefixo NEXT_PUBLIC_).process.env: const { customKey } = process.env não funciona por causa de como o webpack DefinePlugin substitui a expressão.NEXT_PUBLIC_, cuidado com segredos.