Skip to content

Support custom --mode dotenv loading for vinext build #2393

Description

@llc1123

Summary

Next.js itself does not provide a next build --mode <mode> workflow. next build is a production build, and multi-environment builds are usually handled by injecting the desired environment variables before running the build.

For example, our current vinext workaround is:

dotenv -o -e .env.test -- vinext build

That works: the selected dotenv file is loaded into the process first, and vinext can then inline process.env.NEXT_PUBLIC_* values through its Next-compatible env handling.

Request

Since vinext is Vite-based, it would be useful if it optionally supported the Vite-style workflow:

vinext build --mode test

and loaded .env.test* before creating the Vite builder and before computing NEXT_PUBLIC_* defines.

This is not required for strict Next.js compatibility, but it would make non-production vinext builds easier to discover and avoid project-local wrapper scripts for common targets like test, staging, prod, or cdn.

Current behavior

vinext build --mode test currently does not appear to load .env.test; vinext build follows the documented production dotenv behavior instead.

If custom --mode for build is intentionally unsupported, it would be helpful for vinext to document that clearly or reject/warn on --mode, because users familiar with Vite naturally expect build --mode test to select .env.test.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions