Declare the values and their defaults in nuxt.config.ts:
export default defineNuxtConfig({
runtimeConfig: {
apiSecret: '',
public: {
apiBase: '/api',
},
},
})
Then override them with environment variables at runtime, no rebuild needed. The name is NUXT_ plus the key in upper snake case, with PUBLIC_ for the public ones:
NUXT_API_SECRET=abc123
NUXT_PUBLIC_API_BASE=https://api.example.com
Read them with useRuntimeConfig(). Everything under public is sent to the browser; everything else stays on the server. Only NUXT_* variables are picked up, a random API_KEY in .env does nothing.