Skip to content
PluginStats

vite-plugin-require weekly downloads statistics

By wangzongming · npm · Vite plugins

can let vite projects to support require

View on npm Fresh · Dec 6, 2026

vite-plugin-require has 76,204 recorded weekly downloads on npm, an increase of 49.9% over the past 30 days, ranking #686 of 3,247 tracked listings.

Weekly downloads
76,204
Official API · Dec 5, 2026
7-day growth
-7.8%
-6.5K weekly downloads
30-day growth
+49.9%
+25.4K weekly downloads
90-day growth
+82.9%
+34.5K weekly downloads
Rank
#686
▼ 31 in 7 days

About vite-plugin-require

vite-plugin-require npm npm

Let Vite projects support require("xxx") syntax. vite-plugin-require

Install and use to achieve painless support for require("xxx").

If the project is useful to you, please click on star!



Other Projects

The simplest and lowest-cost solution for hardware + AI: https://github.com/wangzongming/esp-ai

Community

QQ Group: 952051286

Supported Vite Versions

  • √ vite2
  • √ vite3
  • √ vite4
  • √ vite5
  • √ vite6
  • √ vite7
  • √ vite8

Install

npm i vite-plugin-require | yarn add vite-plugin-require

Usage

import vue from '@vitejs/plugin-vue'
import vitePluginRequire from "vite-plugin-require";

export default {
	plugins: [
        vue(),

        // Must be placed after the vue plugin
		vitePluginRequire(),

        // vite4、vite5、vite6 (ESM)
        // vitePluginRequire.default()
	],
};

Supported Features

File Types

By default, the plugin transforms files matching /(.jsx?|.tsx?|.vue)$/.

ExtensionSupported
.js / .jsx√
.ts / .tsx√
.vue√ (must be placed after @vitejs/plugin-vue)

Files under node_modules are excluded automatically.

require() Argument Types
1. String Literal

Static path, converted to a top-level import.

<img src={require("./imgs/logo.png")} alt="logo" />
2. Identifier (Variable)

The variable must be initialized with a string literal in the same file. The plugin resolves the variable to a static path at compile time.

const img = "./imgs/logo.png";
<img src={require(img)} alt="logo" />
3. String Concatenation (BinaryExpression)

Supports + concatenation of string literals, variables, and nested expressions.

const prefix = "./imgs/";
const suffix = "logo";
<img src={require(prefix + suffix + ".png")} alt="logo" />
4. Conditional Expression (ConditionalExpression)

Supports ternary expressions inside require().

Both branches are static paths (default translateType: "import"):

The plugin imports both assets and replaces require() with a ternary expression.

<img src={require(isPrimary ? "./imgs/logo-blue.svg" : "./imgs/logo.svg")} alt="logo" />

Either branch is dynamic, or translateType: "importMetaUrl":

Falls back to new URL(..., import.meta.url).href.

<img src={require(isPrimary ? "./imgs/logo-blue.svg" : dynamicPath)} alt="logo" />
5. Template Literal (TemplateLiteral)

No interpolation — treated as a static path:

<img src={require(`./imgs/logo.png`)} alt="logo" />

With interpolation — converted to runtime URL resolution:

<img src={require(`./imgs/${icon}.svg`)} alt="icon" />
// → new URL(`./imgs/${icon}.svg`, import.meta.url).href

<img src={require(`./imgs/${active ? `${name}_active` : name}.svg`)} alt="icon" />
// → new URL(`./imgs/${active ? `${name}_active` : name}.svg`, import.meta.url).href
Path Resolution
  • Relative paths (./, ../) are resolved relative to the current file.
  • Deeply nested directories are supported.
  • Vite resolve.alias is supported.
// src/views/Page1/index.jsx
<img src={require("../../../imgs/logo.png")} alt="logo" />
<img src={require("./imgs/logo.png")} alt="logo" />
// with alias: @imgs → ./src/imgs/
<img src={require("@imgs/logo.png")} alt="logo" />
Conversion Modes (translateType)
ModeDescription
import (default)Hoists static assets to top-level import statements
importMetaUrlConverts to new URL(path, import.meta.url).href. See Vite assets docs

translateType: "import"

All resolvable static require() calls are replaced with top-level imports.

translateType: "importMetaUrl"

Uses import.meta.url instead of import. Supports on-demand loading — the original code is not removed at build time.

Only works when the asset variable exists before rendering:

let imgUrl = process.env.NODE_ENV !== "development" ? require("../imgs/logo.png") : null;

return <>
    { imgUrl ? <img src={imgUrl}/> : null }
</>

Do not put the conditional inside src, e.g. src={xx ? require("../imgs/logo.png") : null}. See issue #28.

Limitations
ScenarioStatus
Variable assigned a non-literal value✗ Cannot resolve
Complex variable reassignment✗ Only simple const x = "path" is supported
require() with unsupported argument types✗ Throws Unsupported type: xxx
require(new URL(...)) (MemberExpression)✗ Not implemented yet

Options

All options are optional.

fileRegex

Files to transform. Default: /(.jsx?|.tsx?|.vue)$/

vitePluginRequire({ fileRegex: /(.jsx?|.tsx?|.vue)$/ })
translateType

Conversion mode. Default: "import"

vitePluginRequire({ translateType: "import" })
vitePluginRequire({ translateType: "importMetaUrl" })
log

Debug logger, receives internal transform info.

vitePluginRequire({ log: (...args) => console.log(...args) })

Demo

Suppose there are app.jsx and imgs folder in the src directory:

// app.jsx
function App() {
    const img2 = "./img/1.png";
    const img3_1 = "./img/";
    const img3_2 = "./1/";
    const icon = "home";…

Description from the npm listing.

  • vite
  • require
  • vite-plugin
  • vite-plugin-require

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-require weekly downloads on npm, last 90 days: 76,204 weekly downloads as of Dec 5, 2026, +82.9% over 90 days.vite-plugin-requireWeekly downloads on npm · Last 90 days76,204downloads / week+82.9% over 90 days020K40K60K80K100KSep 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-require weekly downloads on npm, last 90 days: 76,204 weekly downloads as of Dec 5, 2026, +82.9% over 90 days.

7/30/90-day growth

vite-plugin-require weekly downloads growth on npm: -7.8% over 7 days, +49.9% over 30 days, +82.9% over 90 days.vite-plugin-requireWeekly downloads growth on npm76,204downloads / week now7-day growth-6,450 weekly downloads-7.8%30-day growth+25,381 weekly downloads+49.9%90-day growth+34,540 weekly downloads+82.9%Growth vs. nearest observation to each baseline date · Updated Dec 5, 2026pluginstats.com
vite-plugin-require weekly downloads growth on npm: -7.8% over 7 days, +49.9% over 30 days, +82.9% over 90 days.

Ranking history

vite-plugin-require npm ranking history: currently #686 (by weekly downloads).vite-plugin-requirenpm ranking · by weekly downloads · Last 90 days#686current rank#200#300#400#500#600#700#800#900Sep 7Sep 22Oct 7Oct 22Nov 6Nov 21Dec 6rankOct 17, 2026 – Dec 6, 2026 · 45 observations · Updated Dec 5, 2026pluginstats.com
vite-plugin-require npm ranking history: currently #686 (by weekly downloads).

Listing placement

All npm3,247 listings · 163 pages · 1,084 shown · page 35, #6 (overall #686)
All npm: every listing in weekly downloads order

Listing placement

Vite plugins300 listings · 15 pages · page 6, #17 (overall #117)
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 (592)
Recent weekly downloads observations for vite-plugin-require
Date (UTC)Weekly downloadsChange vs. previous
76,204-78
76,282+4.2K
72,109-1.9K
74,010+2.1K
71,923-4.8K
76,744-4.6K
81,327-1.3K
82,654-258
82,912-5.4K
88,330-5.7K
94,054+4.6K
89,464+10K
79,501+8.6K
70,899—

Similar npm Vite plugins plugins

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