Skip to content
PluginStats

vite-plugin-require-transform weekly downloads statistics

By WarrenJones · npm · Vite plugins

A plugin for vite that convert from require syntax to import that compat for es module.

View on npm Fresh · Dec 6, 2026

vite-plugin-require-transform has 40,141 recorded weekly downloads on npm, a decrease of 25.9% over the past 30 days, ranking #850 of 3,247 tracked listings.

Weekly downloads
40,141
Official API · Dec 5, 2026
7-day growth
+30.9%
+9.5K weekly downloads
30-day growth
-25.9%
-14K weekly downloads
90-day growth
+14.4%
+5.1K weekly downloads
Rank
#850
▲ 40 in 7 days

About vite-plugin-require-transform

vite-plugin-require-transform

NPM

npm version A vite plugin that converts the code from require syntax to import

Why vite-plugin-require-transform

<b>"require syntax"</b> is supported when develop with <b>Webpack</b> cause it transformed it internally.

but when serve with <b>Vite</b> error <b>"require is not defined" </b>will show up.

This plugin amis to support require when serve with vite.

Install

yarn add -D vite-plugin-require-transform

or

npm i vite-plugin-require-transform --save-dev

Usage

// vite.config.(t|j)s

import { defineConfig } from 'vite';

/**
 * @param match
 * Regular expression in string or Regexp type,
 *  or a match predicate  (this: vite transform context, code: string, id: file name string) => void
 * @returns transformed code
 */
import requireTransform from 'vite-plugin-require-transform';

export default defineConfig({
  plugins: [
    // passing string type Regular expression
    requireTransform({}),
  ],
});


// check the vite-plugin-require-transform params'type 
export type VitePluginRequireTransformParamsType = {
	//filter files that should enter the plugin
	fileRegex?: RegExp = /.ts$|.tsx$/ ,
	//prefix that would plugin into the requireSpecifier 
	importPrefix? = '_vite_plugin_require_transform_': string,
	//to deal with the requireSpecifier
	importPathHandler?: Function
}

What vite-plugin-require-transform actually do

you can also check the test directory to see the cases.

case 1:
const case1 = require("case1");
console.log("case1", case1)

will be transformed into

import _vite_plugin_require_transform_case1 from "case1";
const case1 = _vite_plugin_require_transform_case1;
console.log("case1", case1);
case 2:
example A
const case2A = location.host == 'test' ? null : require("case2");

if(location.host == 'test1' ){
    case2A.start();
}

case2A.stop();

will be transformed into

import { start as _vite_plugin_require_transform_case2start, stop as _vite_plugin_require_transform_case2stop } from "case2";
const _vite_plugin_require_transform_case2 = {
  start: _vite_plugin_require_transform_case2start,
  stop: _vite_plugin_require_transform_case2stop
};
const case2A = location.host == 'test' ? null : _vite_plugin_require_transform_case2;

if (location.host == 'test1') {
  case2A.start();
}

case2A.stop();
example B
const case2B = {
    test:require('test2B').Something
}

will be transformed into

import { Something as _vite_plugin_require_transform_test2BSomething } from "test2B";
const case2B = {
  test: _vite_plugin_require_transform_test2BSomething
};
example C
const case2c =require('test2C')


case2c.forEach((item)=>{
    console.log('item',item)
})

will be transformed into

import _vite_plugin_require_transform_test2C from "test2C";
const case2c = _vite_plugin_require_transform_test2C;
case2c.forEach(item => {
  console.log('item', item);
});
case 3:

when exist a case as same fileName,different extensions,by default it would be error cause the plugin only capture the path without extension.


//same path,different extension
const testCaseA = require("caseA.extA?aaa");
const testCaseB = require("caseA.extB?bbb");

console.log("caseA", testCaseA)
console.log("caseB", testCaseB)

so we need to make a importPathHandler to deal with the situtation

//check out __test__/index
glob("__test__/case3/*.ts", {
    ignore: "**/*transformed_result.ts"
}, async (err, files) => {
    for (const file of files) {
        const fileContent = readFileSync(file, 'utf-8');
        const transformedContent = await vitePluginRequireTransform(
            {
                importPathHandler: (requirePath: string) => {
                    return requirePath.replace('.', '_').replace('?', "_");
                }
            }
        ).transform(fileContent, file);
        writeFileSync(file.replace('.ts', '_transformed_result.ts'), transformedContent.code);
    }
})  

will be transformed into

import _vite_plugin_require_transform_caseA_extB_bbb from "caseA.extB?bbb";
import _vite_plugin_require_transform_caseA_extA_aaa from "caseA.extA?aaa";
//same path,different extension
const testCaseA = _vite_plugin_require_transform_caseA_extA_aaa;
const testCaseB = _vite_plugin_require_transform_caseA_extB_bbb;
console.log("caseA", testCaseA);
console.log("caseB", testCaseB);

Description from the npm listing.

  • vite
  • 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-transform weekly downloads on npm, last 90 days: 40,141 weekly downloads as of Dec 5, 2026, +14.4% over 90 days.vite-plugin-require-transformWeekly downloads on npm · Last 90 days40,141downloads / week+14.4% over 90 days010K20K30K40K50K60K70KSep 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-transform weekly downloads on npm, last 90 days: 40,141 weekly downloads as of Dec 5, 2026, +14.4% over 90 days.

7/30/90-day growth

vite-plugin-require-transform weekly downloads growth on npm: +30.9% over 7 days, -25.9% over 30 days, +14.4% over 90 days.vite-plugin-require-transformWeekly downloads growth on npm40,141downloads / week now7-day growth+9,480 weekly downloads+30.9%30-day growth-14,005 weekly downloads-25.9%90-day growth+5,064 weekly downloads+14.4%Growth vs. nearest observation to each baseline date · Updated Dec 5, 2026pluginstats.com
vite-plugin-require-transform weekly downloads growth on npm: +30.9% over 7 days, -25.9% over 30 days, +14.4% over 90 days.

Ranking history

vite-plugin-require-transform npm ranking history: currently #850 (by weekly downloads).vite-plugin-require-transformnpm ranking · by weekly downloads · Last 90 days#850current rank#650#700#750#800#850#900#950Sep 7Sep 22Oct 7Oct 22Nov 6Nov 21Dec 6rankOct 18, 2026 – Dec 6, 2026 · 44 observations · Updated Dec 5, 2026pluginstats.com
vite-plugin-require-transform npm ranking history: currently #850 (by weekly downloads).

Listing placement

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

Listing placement

Vite plugins300 listings · 15 pages · page 8, #9 (overall #149)
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-require-transform
Date (UTC)Weekly downloadsChange vs. previous
40,141+1.4K
38,695+1.6K
37,127+1.3K
35,804+2.1K
33,675+1.4K
32,322+1.8K
30,506-155
30,661+12
30,649-207
30,856-193
31,049-202
31,251-1.3K
32,572-1.1K
33,625—

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