vite-transform-stub

raw JSON →
1.0.1 verified Mon Apr 27 auth: no javascript

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.

error Error: Cannot find module 'vite-transform-stub'
cause Package not installed or npm resolution issue.
fix
Run npm install --save-dev vite-transform-stub or pnpm add -D vite-transform-stub
error TypeError: (0 , vite_transform_stub.stubTransform) is not a function
cause Wrong import style (default import instead of named import).
fix
Use import { stubTransform } from 'vite-transform-stub'
gotcha Plugin 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$/)
deprecated Vite 4.x is required. Vite 5+ may not be compatible.
fix Use a different stub plugin or fork for Vite 5+.
gotcha Plugin 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'.
npm install vite-transform-stub
yarn add vite-transform-stub
pnpm add vite-transform-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()]
});