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:
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.
Summary
Next.js itself does not provide a
next build --mode <mode>workflow.next buildis 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:
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 testand loaded
.env.test*before creating the Vite builder and before computingNEXT_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, orcdn.Current behavior
vinext build --mode testcurrently does not appear to load.env.test;vinext buildfollows the documented production dotenv behavior instead.If custom
--modefor 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 expectbuild --mode testto select.env.test.