fix(build): read VITE_* values by key and refuse undeclared ones (13-06)
getBuildConfig defaulted to the whole import.meta.env, so Vite inlined every loaded VITE_* value, read or not. Values are now read by key, a lint rule bans whole-object references in src, and vite.config refuses VITE_* names missing from ENV_REGISTRY. A build test pins the values that must stay in the bundle. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
a8111f7647
commit
2ec59ad9ee
+11
-1
@@ -120,8 +120,18 @@ export type BuildEnvironment = Readonly<{
|
||||
VITE_RUNTIME_CONFIG_URL?: string;
|
||||
}>;
|
||||
|
||||
/**
|
||||
* 13-06. Each variable is read by key so Vite replaces it on its own. Passing
|
||||
* `import.meta.env` whole made Vite inline every loaded VITE_* value, read or
|
||||
* not, into this module's chunk.
|
||||
*/
|
||||
export function getBuildConfig(
|
||||
environment: BuildEnvironment = import.meta.env as BuildEnvironment,
|
||||
environment: BuildEnvironment = {
|
||||
VITE_BUILD_ID: import.meta.env.VITE_BUILD_ID,
|
||||
VITE_COMMIT_SHA: import.meta.env.VITE_COMMIT_SHA,
|
||||
VITE_ROUTER_BASE_PATH: import.meta.env.VITE_ROUTER_BASE_PATH,
|
||||
VITE_RUNTIME_CONFIG_URL: import.meta.env.VITE_RUNTIME_CONFIG_URL,
|
||||
},
|
||||
) {
|
||||
const buildId = environment.VITE_BUILD_ID || "local-build";
|
||||
const commitSha = environment.VITE_COMMIT_SHA || "local";
|
||||
|
||||
Reference in New Issue
Block a user