
Product
Introducing Reports: An Extensible Reporting Framework for Socket Data
Explore exportable charts for vulnerabilities, dependencies, and usage with Reports, Socket’s new extensible reporting framework.
vite-plugin-meta-env
Advanced tools
English | 简体中文
define dynamic env variables in import.meta.env
This plugin is used in vite , Expose dynamic or without prefix environment variables in the project
a、dynamicenvironment variables
b、without prefixenvironment variables
In vite projects, the environment variable is usually exposed which is starting with envPrefix The default is VITE_,
such as: VITE_API_URL, VITE_APP_NAME and so on.
But sometimes you need to use some dynamic environment variables and variables without prefix such as: APP_VERSION, APP_BUILD_TIME and so on.
This plugin is born to solve this problem.
Here we use the config and define configuration options unique to vite to complete this function
pnpm add vite-plugin-meta-env -D
VitePluginMetaEnv receives two parameters:
/**
* Use the define option to expose a variable without a prefix
* @param {EnvVars} Vars environment variable object
* @param defineOn Variable Definition Location
*/
key is the variable name, value is the variable value.import.meta.env or process.env// vite.config.js
import { defineConfig } from 'vite'
// import plugin
import VitePluginMetaEnv from 'vite-plugin-meta-env'
export default () => {
// environment variables, object structure
const metaEnv = {
APP_VERSION: '1.0.0'
}
return defineConfig({
// ...
plugins: [
// use plugin
VitePluginMetaEnv(metaEnv, 'import.meta.env'),
// VitePluginMetaEnv(metaEnv, 'process.env'),
]
})
}
in the project, you can access the environment variables we defined through import.meta.env.APP_VERSION
to ensure type checking and code hints, please add type declarations in env.d.ts or vite-env.d.ts
// env.d.ts
/// <reference types="vite/client" />
interface ImportMetaEnv {
readonly BASE_URL: string // Built-in variable
readonly MODE: string // Built-in variable
readonly APP_VERSION: string
// more...
}
interface ImportMeta {
readonly env: ImportMetaEnv
}
FAQs
a vite plugin, define dynamic env variables in import.meta.env
The npm package vite-plugin-meta-env receives a total of 1,865 weekly downloads. As such, vite-plugin-meta-env popularity was classified as popular.
We found that vite-plugin-meta-env demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Explore exportable charts for vulnerabilities, dependencies, and usage with Reports, Socket’s new extensible reporting framework.

Product
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.