Skip to content
PluginStats

vite-env-only weekly downloads statistics

By pcattori · npm · Vite plugins

Vite plugins for isolating server-only and client-only code

View on npm Fresh · Dec 6, 2026

vite-env-only has 122,335 recorded weekly downloads on npm, an increase of 3.5% over the past 30 days, ranking #610 of 3,247 tracked listings.

Weekly downloads
122,335
Official API · Dec 5, 2026
7-day growth
-1.4%
-1.8K weekly downloads
30-day growth
+3.5%
+4.2K weekly downloads
90-day growth
+36.7%
+32.8K weekly downloads
Rank
#610
▼ 24 in 7 days

About vite-env-only

ci workflow

vite-env-only

Vite plugins for isolating server-only and client-only code

Install

npm install -D vite-env-only

Deny Imports

Prevents specific packages and files from being included in the client or server bundle by throwing an error at build-time when a matching import would have been included.

// vite.config.ts
import { defineConfig } from "vite"
import { denyImports } from "vite-env-only"

export default defineConfig({
  plugins: [
    denyImports({
      client: {
        specifiers: ["fs-extra", /^node:/, "@prisma/*"],
        files: ["**/.server/*", "**/*.server.*"],
      },
      server: {
        specifiers: ["jquery"],
      },
    }),
  ],
})
{
  client?: {
    specifiers?: Array<string | RegExp>,
    files?: Array<string | RegExp>
  },
  server?: {
    specifiers?: Array<string | RegExp>,
    files?: Array<string | RegExp>
  }
}
specifiers

Matching is performed against the raw import specifier in the source code. Match patterns can be:

  • String literal for exact matches
  • Globs via micromatch
  • RegExps
files

Matching is performed against the resolved and normalized root-relative file path. Match patterns can be:

  • String literal for exact matches
  • Globs via micromatch
  • RegExps

Macros

// vite.config.ts
import { defineConfig } from "vite"
import { envOnlyMacros } from "vite-env-only"

export default defineConfig({
  plugins: [envOnlyMacros()],
})

All macros can be imported within your app code from "vite-env-only/macros".

serverOnly$

Marks an expression as server-only and replaces it with undefined on the client. Keeps the expression as-is on the server.

For example:

import { serverOnly$ } from "vite-env-only/macros"

export const message = serverOnly$("i only exist on the server")

On the client this produces:

export const message = undefined

On the server this produces:

export const message = "i only exist on the server"
clientOnly$

Marks an expression as client-only and replaces it with undefined on the server. Keeps the expression as-is on the client.

For example:

import { clientOnly$ } from "vite-env-only/macros"

export const message = clientOnly$("i only exist on the client")

On the client this produces:

export const message = "i only exist on the client"

On the server this produces:

export const message = undefined
Dead-code elimination

This plugin eliminates any identifiers that become unreferenced as a result of macro replacement.

For example, given the following usage of serverOnly$:

import { serverOnly$ } from "vite-env-only/macros"
import { readFile } from "node:fs"

function readConfig() {
  return JSON.parse(readFile.sync("./config.json", "utf-8"))
}

export const serverConfig = serverOnly$(readConfig())

On the client this produces:

export const serverConfig = undefined

On the server this produces:

import { readFile } from "node:fs"

function readConfig() {
  return JSON.parse(readFile.sync("./config.json", "utf-8"))
}

export const serverConfig = readConfig()
Type safety

The macro types capture the fact that values can be undefined depending on the environment.

For example:

import { serverOnly$ } from "vite-env-only/macros"

export const API_KEY = serverOnly$("secret")
//           ^? string | undefined

If you want to opt out of strict type safety, you can use a non-null assertion (!):

import { serverOnly$ } from "vite-env-only/macros"

export const API_KEY = serverOnly$("secret")!
//           ^? string
Why?

Vite already provides import.meta.env.SSR which works in a similar way to these macros in production. However, in development Vite neither replaces import.meta.env.SSR nor performs dead-code elimination as Vite considers these steps to be optimizations.

In general, its a bad idea to rely on optimizations for correctness. In contrast, these macros treat code replacement and dead-code elimination as part of their feature set.

Additionally, these macros use function calls to mark expressions as server-only or client-only. That means they can guarantee that code within the function call never ends up in the wrong environment while only transforming a single AST node type: function call expressions.

import.meta.env.SSR is instead a special identifier which can show up in many different AST node types: if statements, ternaries, switch statements, etc. This makes it far more challenging to guarantee that dead-code completely eliminated.

Prior art

Thanks to these project for exploring environment isolation and conventions for transpilation:

Description from the npm listing.

  • vite-plugin
  • env
  • only
  • client
  • server
  • macro
  • deny
  • imports

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-env-only weekly downloads on npm, last 90 days: 122,335 weekly downloads as of Dec 5, 2026, +36.7% over 90 days.vite-env-onlyWeekly downloads on npm · Last 90 days122,335downloads / week+36.7% over 90 days020K40K60K80K100K120K140K160KSep 6Sep 21Oct 6Oct 21Nov 5Nov 20Dec 5downloads / weekobservedarchived (Internet Archive)no observationsSep 7, 2026 – Dec 5, 2026 · 90 observations · Updated Dec …pluginstats.com
vite-env-only weekly downloads on npm, last 90 days: 122,335 weekly downloads as of Dec 5, 2026, +36.7% over 90 days.

7/30/90-day growth

vite-env-only weekly downloads growth on npm: -1.4% over 7 days, +3.5% over 30 days, +36.7% over 90 days.vite-env-onlyWeekly downloads growth on npm122,335downloads / week now7-day growth-1,772 weekly downloads-1.4%30-day growth+4,177 weekly downloads+3.5%90-day growth+32,845 weekly downloads+36.7%Growth vs. nearest observation to each baseline date · Updated Dec 5, 2026pluginstats.com
vite-env-only weekly downloads growth on npm: -1.4% over 7 days, +3.5% over 30 days, +36.7% over 90 days.

Ranking history

vite-env-only npm ranking history: currently #610 (by weekly downloads).vite-env-onlynpm ranking · by weekly downloads · Last 90 days#610current rank#540#550#560#570#580#590#600#610#620Sep 7Sep 22Oct 7Oct 22Nov 6Nov 21Dec 6rankOct 18, 2026 – Dec 6, 2026 · 44 observations · Updated Dec 5, 2026pluginstats.com
vite-env-only npm ranking history: currently #610 (by weekly downloads).

Listing placement

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

Listing placement

Vite plugins300 listings · 15 pages · page 5, #18 (overall #98)
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-env-only
Date (UTC)Weekly downloadsChange vs. previous
122,335-1.3K
123,654+1.7K
121,975+9.1K
112,890+318
112,572-7K
119,560-4.9K
124,504+397
124,107-1.5K
125,612-5K
130,609-2.5K
133,074+1.1K
131,987+5.4K
126,612+1.1K
125,533—

Similar npm Vite plugins plugins

All 20 vite-env-only 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-env-only. First seen Oct 16, 2026; last successful collection Dec 6, 2026. See the methodology.