Registry / web-framework / vite-vanjs-svg

vite-vanjs-svg

JSON →
library0.0.14jsnpmunverified

A Vite plugin that transforms SVG files into VanJS components using DOMParser. Version 0.0.14 is the latest stable release with active development. It supports TypeScript, HMR, configurable include/exclude filters, and uses oxc/esbuild for transformation. Compared to alternatives, it is specifically designed for VanJS, providing fast transformation and type safety without runtime overhead.

npm install vite-vanjs-svg
INSTALL
IMPORT
SIG · VITE-VANJS-SVG
V
vite-vanjs-svg
web-frameworkjavascriptv0.0.14
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.

vanSVG
import vanSVG from 'vite-vanjs-svg'
const vanSVG = require('vite-vanjs-svg')
ESM only; also works with default import for Vite config.
VitePluginVanSvgOptions
import type { VitePluginVanSvgOptions } from 'vite-vanjs-svg'
import { VitePluginVanSvgOptions } from 'vite-vanjs-svg'
Only exported as type; import with 'type' modifier to avoid runtime issues.
Icon default import
import Icon from './icon.svg?van'
import { Icon } from './icon.svg?van'
SVG with query ?van is imported as default export; named import will fail.

Configure the Vite plugin, add TypeScript declarations, and use an imported SVG as a VanJS component.

// vite.config.ts import { defineConfig } from 'vite'; import vanSVG from 'vite-vanjs-svg'; export default defineConfig({ plugins: [ vanSVG({ // Optional: include: ['**/*.svg?van'], // exclude: undefined, // esbuildOptions: {}, // oxcOptions: {}, }), ], }); // src/vite-env.d.ts /// <reference types="vite/client" /> /// <reference types="vite-vanjs-svg" /> // App.tsx (example with VanJS) import van from 'vanjs-core'; import Icon from './icon.svg?van'; const { div } = van.tags; const App = () => { return div( Icon({ width: 24, height: 24, class: 'my-icon', style: 'fill: currentColor' }) ); }; document.body.appendChild(App());
Debug
Known issues
deprecatedesbuildOptions is deprecated since version 0.0.14; use oxcOptions instead.
fix
Replace esbuildOptions with oxcOptions in plugin configuration.
affects: >=0.0.14
breakingComponents are now ES modules with sourcemaps; if you rely on UMD or CommonJS output, this may break imports.
fix
Ensure your project uses ESM-compatible bundler settings.
affects: >=0.0.11
gotchaThe style attribute only supports string values; object or array style values will not work.
fix
Pass style as a string (e.g., 'fill: red').
affects: >=0.0.8
gotchaInclude filter defaults to ['**/*.svg?van']; if you omit ?van query, SVGs won't be transformed.
fix
Append ?van to SVG import paths or customize include option.
affects: >=0.0.8
Errors
Common errors & fixes
Cannot find module 'vite-vanjs-svg' or its corresponding type declarations.
Missing TypeScript type reference or package not installed as devDependency.
fix
Run npm install -D vite-vanjs-svg and add /// <reference types="vite-vanjs-svg" /> to your vite-env.d.ts.
Uncaught (in promise) TypeError: van is not a function
Attempting to use SVG component outside of VanJS context or missing VanJS import.
fix
Ensure vanjs-core or vanjs-ui is imported and van.tags is available.
[plugin:vite-vanjs-svg] The 'style' attribute only supports string value.
Passing an object (e.g., style={{ fill: 'red' }}) instead of a string.
fix
Change style to a string like 'fill: red'.
Failed to load url ./icon.svg?van (doesn't exist)
SVG file path is incorrect or missing the ?van query.
fix
Verify the SVG path and ensure the import ends with ?van.
Upgrade
Version history
0.0.14latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources
vite-vanjs-svg — npm install vite-vanjs-svg · libregistry