vite-syntax-env-vars

Manage Vite environment variables with .env file precedence and VITE_ prefix rules.

4|Updated Mar 20, 2026
One-click install
npx skills add https://github.com/OpenAEC-Foundation/OpenAEC-Workspace-Composer --skill vite-syntax-env-vars
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: vite-syntax-env-vars
Source: https://github.com/OpenAEC-Foundation/OpenAEC-Workspace-Composer/tree/main/.claude/skills/vite/vite-syntax/vite-syntax-env-vars
Command: npx skills add https://github.com/OpenAEC-Foundation/OpenAEC-Workspace-Composer --skill vite-syntax-env-vars

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Use when configuring environment variables, using .env files, creating custom modes, or debugging env variable issues. Prevents exposing secrets by omitting the VITE_ prefix and misconfiguring .env file precedence. Covers import.meta.env built-ins, .env file loading order, VITE_ prefix requirement, dotenv-expand, custom modes, NODE_ENV vs mode, ImportMetaEnv TypeScript, HTML %ENV%, and loadEnv().

Core Features & Use Cases

  • Understand import.meta.env built-ins and their runtime vs build-time behavior.
  • Master the .env loading order across development, production, and custom modes, including OS env overrides.
  • Enforce safe exposure by prefixing client vars with VITE_ and using loadEnv(), TS typings, and HTML replacements.
  • Practical scenarios: configuring dev servers, enabling custom modes, and debugging env-related issues.

Quick Start

Configure your project to expose only VITE_-prefixed variables and verify env loading order by inspecting import.meta.env in your app.

Frequently Asked Questions about vite-syntax-env-vars

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent exposing secrets when using environment variables in Vite?

To safeguard env vars in Vite, expose only variables prefixed with VITE_ to the client. Omitting this prefix prevents secrets from leaking into the client bundle via import.meta.env.

What is the loading order of .env files for custom modes in Vite?

Vite loads .env files based on the active mode, prioritizing mode-specific files like .env.production. OS environment variables override loaded .env file values, ensuring flexible configuration.

How do I use loadEnv() to access environment variables in Vite?

Use loadEnv() in your Vite config to read environment variables before the app initializes. It loads variables from .env files based on the specified mode without exposing them to the client.

What is the difference between NODE_ENV and mode in Vite?

NODE_ENV defines the build environment, while mode targets the specific configuration preset like development or production. Custom modes can be enabled using the --mode flag to load distinct .env files.

How do I type import.meta.env in TypeScript for Vite projects?

Type import.meta.env using ImportMetaEnv interface in TypeScript. Define your VITE_-prefixed variables in this interface to get accurate autocomplete and type checking across your Vite project.

Can I use dotenv-expand interpolation with VITE_ environment variables?

Yes, dotenv-expand expands variable references within your .env files. This allows you to reference existing variables when defining new VITE_-prefixed environment variables in Vite.