Registry / testing / vite-transform-stub

vite-transform-stub

JSON →
library1.0.1jsnpmunverified

Vite plugin to stub non-JS/TS asset imports (e.g., SVG, CSS, images) during testing or builds. Version 1.0.1, released March 2023, stable. Designed for Vite 4.x compatibility and ships TypeScript definitions. Key differentiator: simple, zero-config stub that returns an empty string by default, usable in Vitest or Vite config. Alternative to `vite-plugin-stub` or manually mocking every asset.

npm install vite-transform-stub
INSTALL
IMPORT
SIG · VITE-TRANSFORM-STU
V
vite-transform-stub
testingjavascriptv1.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

stubTransform
import { stubTransform } from 'vite-transform-stub'
import stubTransform from 'vite-transform-stub'
Named export, not default. ESM only; no CommonJS support.
stubTransform
import { stubTransform } from 'vite-transform-stub'
const { stubTransform } = require('vite-transform-stub')
Package is ESM-only; require() will fail.
stubTransform
import { stubTransform } from 'vite-transform-stub'
import { stub } from 'vite-transform-stub'
The exported function is named stubTransform, not stub.

Install plugin and add to Vite config to stub all non-JS/TS asset imports.

npm install --save-dev vite-transform-stub // vite.config.ts import { defineConfig } from 'vite'; import { stubTransform } from 'vite-transform-stub'; export default defineConfig({ plugins: [stubTransform()] });
Debug
Known issues
gotchaPlugin stubs all non-JS/TS assets by default only if no filter is provided. This may unintentionally stub assets you actually need.
fix
Pass a RegExp filter to stubTransform() to specify which extensions to stub, e.g., stubTransform(/\.svg$/)
affects: >=1.0.0
deprecatedVite 4.x is required. Vite 5+ may not be compatible.
fix
Use a different stub plugin or fork for Vite 5+.
affects: >=1.0.0
gotchaPlugin returns an empty string for all stubbed files, which may break tests expecting a URL or object.
fix
Alternatively, use a more configurable stub plugin like 'vite-plugin-stub'.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'vite-transform-stub'
Package not installed or npm resolution issue.
fix
Run npm install --save-dev vite-transform-stub or pnpm add -D vite-transform-stub
TypeError: (0 , vite_transform_stub.stubTransform) is not a function
Wrong import style (default import instead of named import).
fix
Use import { stubTransform } from 'vite-transform-stub'
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
viterequiredpeer dependency for plugin API
Agent activity
20 hits · last 30 days
node
16
OpenAI (training)
1
Resources
vite-transform-stub — npm install vite-transform-stub · libregistry