Registry / web-framework / rollup-plugin-svg-to-vue

rollup-plugin-svg-to-vue

JSON →
library1.0.0jsnpmunverified

A Rollup plugin that imports SVG files as Vue 3 components. Current stable version is 1.0.0. No release cadence documented. Key differentiator: transforms SVG directly into Vue 3 single-file component format, leveraging @vue/compiler-sfc for compilation. Unlike generic SVG loaders, it produces tree-shakable, scoped-style components. Primarily for use with rollup-plugin-vue in browser or SSR builds. Requires Node >=10, peer dependency on @vue/compiler-sfc.

npm install rollup-plugin-svg-to-vue
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-SVG-
R
rollup-plugin-svg-to-vue
web-frameworkjavascriptv1.0.0
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.

default (svgToVue)
import svgToVue from 'rollup-plugin-svg-to-vue'
const svgToVue = require('rollup-plugin-svg-to-vue')
ESM-only; CommonJS require will fail because package does not export a CJS bundle.
svgToVue (named)
import { svgToVue } from 'rollup-plugin-svg-to-vue'
Named export is not available — only default export. Using named will result in undefined.
vue file import
import MyIcon from './icon.svg'
After plugin configuration, importing .svg files returns a Vue component object. Works in Rollup with Vue plugin.

Demonstrates Rollup configuration using the plugin with optional SVGO settings, and a Vue component importing an SVG file as a component.

// rollup.config.js import svgToVue from 'rollup-plugin-svg-to-vue'; import vue from 'rollup-plugin-vue'; export default { input: 'src/main.js', output: { file: 'dist/bundle.js', format: 'esm' }, plugins: [ svgToVue({ include: '**/*.svg', exclude: ['node_modules/**'], svgo: { plugins: [ { removeViewBox: false }, { removeTitle: true } ] }, sourceMap: true, target: 'browser' }), vue() ] }; // MyComponent.vue <template> <div> <MyIcon class="icon" /> </div> </template> <script> import MyIcon from './icon.svg'; export default { components: { MyIcon } } </script>
Debug
Known issues
breakingPackage is ESM-only; does not provide a CommonJS build. Require() will throw 'ERR_REQUIRE_ESM'.
fix
Use import syntax or configure Rollup to handle ESM dependencies.
affects: >=1.0.0
deprecatedPlugin relies on rollup-plugin-vue; future versions of Rollup may bundle Vue support differently.
fix
Monitor rollup-plugin-vue compatibility. Consider using @vitejs/plugin-vue if migrating to Vite.
affects: >=1.0.0
gotchaSVGO options passed directly; some SVGO config changes may break SVG rendering in unexpected ways.
fix
Test SVGO transformations thoroughly. Use removeViewBox: false if resizing issues appear.
affects: >=1.0.0
gotchaWhen target is 'node', the generated component uses SSR-compatible render functions; may differ from browser behavior.
fix
Ensure appropriate polyfills for document/global in SSR environment.
affects: >=1.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module not supported.
Package is ESM-only but loaded via CommonJS require.
fix
Use import syntax or set "type": "module" in package.json, or use dynamic import().
TypeError: svgToVue is not a function
Importing named export 'svgToVue' but package only exports default.
fix
Use default import: import svgToVue from 'rollup-plugin-svg-to-vue'
[plugin:vue] [Vue warn]: Component is missing template or render function.
SVG file not processed by plugin; possibly include/exclude pattern incorrect.
fix
Check include pattern in svgToVue options matches SVG file path.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
@vue/compiler-sfcrequiredPeer dependency for compiling Vue 3 single-file components
rollup-plugin-vueoptionalOften used alongside for full Vue single-file component support; not a formal dependency
Agent activity
10 hits · last 30 days
node
8
Resources
rollup-plugin-svg-to-vue — npm install rollup-plugin-svg-to-vue · libregistry