Skip to content
PluginStats

vite-plugin-environment weekly downloads statistics

By ElMassimo (8 listings) · npm · Vite plugins

Easily expose environment variables in Vite.js

View on npm Fresh · Dec 6, 2026

vite-plugin-environment has 545,273 recorded weekly downloads on npm, an increase of 1.1% over the past 30 days, ranking #388 of 3,247 tracked listings.

Weekly downloads
545,273
Official API · Dec 5, 2026
7-day growth
+19.4%
+88.5K weekly downloads
30-day growth
+1.1%
+5.7K weekly downloads
90-day growth
+32.2%
+132.9K weekly downloads
Rank
#388
▲ 9 in 7 days

About vite-plugin-environment

<h2 align='center'><samp>vite-plugin-environment</samp></h2> <p align='center'>Expose environment variables to your client code in <samp>Vite.js</samp></p> <p align='center'> <a href='https://www.npmjs.com/package/vite-plugin-environment'> <img src='https://img.shields.io/npm/v/vite-plugin-environment?color=222&style=flat-square'> </a> <a href='https://github.com/ElMassimo/vite-plugin-environment/blob/main/LICENSE.txt'> <img src='https://img.shields.io/badge/license-MIT-blue.svg'> </a> </p> <br>

Why? 🤔

Although Vite.js provides its own mechanism for exposing environment variables through import.meta.env, sometimes it's not possible or desirable to prefix variables with VITE_.

This plugin is a shorthand for exposing environment variables by configuring <kbd>define</kbd>.

It provides the same functionality as webpack's <kbd>EnvironmentPlugin</kbd>, but for Vite.js.

Installation 💿

Install the package as a development dependency:

npm i -D vite-plugin-environment # yarn add -D vite-plugin-environment

Usage 🚀

You can provide a list of environment variable names to expose to your client code:

import { defineConfig } from 'vite'
import EnvironmentPlugin from 'vite-plugin-environment'

export default defineConfig({
  plugins: [
    EnvironmentPlugin(['API_KEY', 'DEBUG']),
  ],
})

And then use them as:

const apiKey = process.env.API_KEY
Usage with default values

You may instead provide an object which maps keys to their default values.

The default value for a key is only used if the variable is not defined.

EnvironmentPlugin({
  // Uses 'development' if the NODE_ENV environment variable is not defined.
  NODE_ENV: 'development',

  // Have in mind that variables coming from process.env are always strings.
  DEBUG: 'false',

  // Required: will fail if the API_KEY environment variable is not provided.
  API_KEY: undefined, 
 
  // Optional: will not fail if the APP_VERSION environment variable is missing.
  APP_VERSION: null,
}),

Use null for optional variables, or undefined for variables that must be provided.

Configuration ⚙️

Have in mind that you can add the plugin several times—passing different options to load different sets of variables.

Loading prefixed variables

In some cases, it's useful to load all environment variables with a certain prefix.

You can achieve that by passing 'all' and providing the <kbd>prefix</kbd> option.

EnvironmentPlugin('all', { prefix: 'VUE_APP_' }),
EnvironmentPlugin('all', { prefix: 'REACT_APP_' }),

and then use it as usual:

process.env.VUE_APP_NOT_SECRET_CODE
Exposing variables differently

When porting apps to Vite or using SSR it can be useful to expose variables in process.env, which is the default.

In other cases, you may use the <kbd>defineOn</kbd> option to expose them in a different object, such as import.meta.env.

EnvironmentPlugin({ APP_VERSION: 'local' }, { defineOn: 'import.meta.env' }),

and then use it as:

const version = import.meta.env.APP_VERSION
Ignoring .env files

By default the plugin will load .env files using the same strategy as Vite.js.

If you want to ignore .env files and only use values in process.env, you can opt out:

EnvironmentPlugin(['API_KEY'], { loadEnvFiles: false }),

Inside the box 📦

The first example in this README is equivalent to manually configuring:

import { defineConfig } from 'vite'

export default defineConfig({
  define: {
    'process.env.API_KEY': JSON.stringify(process.env.API_KEY),
    'process.env.DEBUG': JSON.stringify(process.env.DEBUG),
  }
})

except it will also use any variables provided by your .env files, and will fail if any of the specified variables is not defined.

Acknowledgements

I created this library only because I wanted something that:

  • Reused Vite's loadEnv functionality, making the library very light (no dependencies).
  • Allowed to provide a subset of variables to expose, and their defaults.

The following libraries might be helpful depending on your use case:

License

This library is available as open source under the terms of the MIT License.

Description from the npm listing.

  • env
  • environment
  • variables
  • vite
  • vite-plugin
  • vitejs

README badge

Show your rank in a README or on your website. The badge updates automatically.

Charts

Images: 30d · 1y · all time · 1600×900 dark

Adoption over time

vite-plugin-environment weekly downloads on npm, last 90 days: 545,273 weekly downloads as of Dec 5, 2026, +32.2% over 90 days.vite-plugin-environmentWeekly downloads on npm · Last 90 days545,273downloads / week+32.2% over 90 days0100K200K300K400K500K600KSep 6Sep 21Oct 6Oct 21Nov 5Nov 20Dec 5downloads / weekobservedarchived (Internet Archive)no observationsSep 7, 2026 – Dec 5, 2026 · 90 observations · Updated Dec …pluginstats.com
vite-plugin-environment weekly downloads on npm, last 90 days: 545,273 weekly downloads as of Dec 5, 2026, +32.2% over 90 days.

7/30/90-day growth

vite-plugin-environment weekly downloads growth on npm: +19.4% over 7 days, +1.1% over 30 days, +32.2% over 90 days.vite-plugin-environmentWeekly downloads growth on npm545,273downloads / week now7-day growth+88,479 weekly downloads+19.4%30-day growth+5,698 weekly downloads+1.1%90-day growth+132,882 weekly downloads+32.2%Growth vs. nearest observation to each baseline date · Updated Dec 5, 2026pluginstats.com
vite-plugin-environment weekly downloads growth on npm: +19.4% over 7 days, +1.1% over 30 days, +32.2% over 90 days.

Ranking history

vite-plugin-environment npm ranking history: currently #388 (by weekly downloads).vite-plugin-environmentnpm ranking · by weekly downloads · Last 90 days#388current rank#340#350#360#370#380#390#400Sep 7Sep 22Oct 7Oct 22Nov 6Nov 21Dec 6rankOct 18, 2026 – Dec 6, 2026 · 44 observations · Updated Dec 5, 2026pluginstats.com
vite-plugin-environment npm ranking history: currently #388 (by weekly downloads).

Listing placement

All npm3,247 listings · 163 pages · 1,083 shown · page 20, #8 (overall #388)
All npm: every listing in weekly downloads order

Listing placement

Vite plugins300 listings · 15 pages · page 3, #14 (overall #54)
Vite plugins: every listing in weekly downloads order

Filled points are observed values; hollow points come from Internet Archive snapshots of the listing page. Dashed segments span periods with no observations — values between points are not interpolated.

Each band is one page of 20. Weekly downloads on a linear scale. Placement is projected from weekly downloads, so it can differ from the marketplace's own sort order. Hover a dot to see the listing.

Recent observations

Full history (170)
Recent weekly downloads observations for vite-plugin-environment
Date (UTC)Weekly downloadsChange vs. previous
545,273+7.9K
537,415+27.5K
509,941+29.2K
480,715+9.4K
471,350+14.8K
456,538+2.6K
453,937-2.9K
456,794-7.1K
463,876-27.8K
491,717-33.6K
525,332-24.5K
549,795-13.5K
563,256-10.8K
574,077—

Similar npm Vite plugins plugins

All 20 vite-plugin-environment alternatives

Data source

Weekly downloads (trailing 7 complete days) come from the official npm downloads API. Downloads include CI and mirrors and are not equivalent to installs or users. npm publishes no ratings.

Listing: https://www.npmjs.com/package/vite-plugin-environment. First seen Oct 16, 2026; last successful collection Dec 6, 2026. See the methodology.