feat(vite): select env from VITE_ENV var instead of requiring --mode#26
Merged
Conversation
The envConfig() plugin now reads VITE_ENV — from process.env and .env* files via Vite's loadEnv, inline values winning over file values — to pick the #config file and the __ENV_NAME__ build constant, falling back to Vite's mode when unset or empty. The var name is configurable via the new envVar option (default "VITE_ENV"). Additive and backward-compatible: --mode keeps working unchanged. Includes tests, a minor changeset, docs, and the landing version bump to v0.5.0. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
Preview releaseLatest commit: Some packages have been released:
Note Use the PR number as tag to install any package. For instance: |
…rding The envConfig error message changed from `...for mode "x"` to `...for env "x"`; update the assertion to match. Also add an e2e test proving VITE_ENV overrides --mode through the real packed plugin. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The
envConfig()Vite plugin can now select the env from aVITE_ENVenv var instead of requiring--mode. Purely additive and backward-compatible.# These are now equivalent: VITE_ENV=staging vite build vite build --mode stagingWhy
Threading
--mode <env>through every command is friction, especially in CI/CD or when the env is already expressed as an env var (or lives in a.env*file). This lets a singleVITE_ENVdrive both the#configdiscovery and the__ENV_NAME__build constant — aligning the build side withenvName()'s precedence chain, which already understoodVITE_ENV.How
resolveEnvName()uses Vite'sloadEnv(mode, cwd, envVar), soVITE_ENVis read fromprocess.envand.env*files (inline/shell values win over file values). Falls back to Vite'smodewhen unset or empty — sovite build --mode stagingkeeps working unchanged.#configalias discovery and the__ENV_NAME__definenow use the resolved env (renamedresolvedMode→resolvedEnv; error message now saysenv).envVaroption (default"VITE_ENV") to rename the var.Tests
Added a
VITE_ENV resolutionblock: precedence overmode, fallback when unset, empty string treated as unset, and a customenvVar. 93/93 pass, typecheck + lint clean.Docs & release
0.4.0→0.5.0).custom-modes,spa-vite-plugin),concepts/env-name, and theviteAPI reference.v0.5.0(anticipating the release).🤖 Generated with Claude Code