Generate Environment Runtime File
The generate-env command creates a runtime environment file at public/__env.js.
This is useful when your frontend reads public environment values at runtime instead of baking all values at build-time.
Command
pnpm exec leadcms generate-env
What it does
- Loads variables from
.envand.env.local. - Filters keys by
NEXT_PUBLIC_prefix. - Writes the result to
public/__env.jsin the form:
window.__env = {
NEXT_PUBLIC_EXAMPLE: "value"
};
Typical usage
Run it before starting or building your app when runtime env injection is required:
pnpm exec leadcms pull
pnpm exec leadcms generate-env
In many projects, this is added to prebuild or deployment scripts.
Best practices
- Keep secrets out of
NEXT_PUBLIC_variables. - Regenerate
__env.jswhen public env values change. - Commit or ignore
public/__env.jsaccording to your deployment strategy.