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-stubVerified import paths — ran on the pinned version, not inferred.
Install plugin and add to Vite config to stub all non-JS/TS asset imports.
Pass a RegExp filter to stubTransform() to specify which extensions to stub, e.g., stubTransform(/\.svg$/)
Use a different stub plugin or fork for Vite 5+.
Alternatively, use a more configurable stub plugin like 'vite-plugin-stub'.
Run npm install --save-dev vite-transform-stub or pnpm add -D vite-transform-stub
Use import { stubTransform } from 'vite-transform-stub'