vite-svg-loader

Vite plugin to load SVG files as Vue components
28,813,015 701
Install
npm install vite-svg-loader
Latest Version:5.1.3
Vue:3
License:MIT
Last Updated:Sep 1, 2026
Links: GitHub  ·  npm
Maintainer: jpkleemans

Vite SVG loader

Vite plugin to load SVG files as Vue components, using SVGO for optimization.

Version Downloads License

<template>
  <MyIcon />
</template>

<script setup>
import MyIcon from './my-icon.svg'
</script>

Install

npm install vite-svg-loader --save-dev

Setup

vite.config.js
import svgLoader from 'vite-svg-loader'

export default defineConfig({
  plugins: [vue(), svgLoader()]
})

Import params

URL

SVGs can be imported as URLs using the ?url suffix:

import iconUrl from './my-icon.svg?url'
// 'data:image/svg+xml...'

Raw

SVGs can be imported as strings using the ?raw suffix:

import iconRaw from './my-icon.svg?raw'
// '<?xml version="1.0"?>...'

Component

SVGs can be explicitly imported as Vue components using the ?component suffix:

import IconComponent from './my-icon.svg?component'
// <IconComponent />

Default import config

When no explicit params are provided SVGs will be imported as Vue components by default. This can be changed using the defaultImport config setting, such that SVGs without params will be imported as URLs (or raw strings) instead.

vite.config.js
svgLoader({
  defaultImport: 'url' // or 'raw'
})

SVGO Configuration

vite.config.js
svgLoader({
  svgoConfig: {
    multipass: true
  }
})

Disable SVGO

vite.config.js
svgLoader({
  svgo: false
})

Skip SVGO for a single file

SVGO can be explicitly disabled for one file by adding the ?skipsvgo suffix:

import IconWithoutOptimizer from './my-icon.svg?skipsvgo'
// <IconWithoutOptimizer />

Use with TypeScript

If you use the loader in a Typescript project, you'll need to reference the type definitions inside vite-env.d.ts:

/// <reference types="vite/client" />
/// <reference types="vite-svg-loader" />

Sponsors

Nexxtmove Logo

Thanks to Nexxtmove for sponsoring the development of this project.
Your logo or name here? Sponsor this project.

Related Packages

@anyone-dev/vite-svg-loader

Vite plugin to load SVG files as Vue components

28,465 701
@kingyue/vite-plugin-vue2-svg

Vite plugin to load SVG files as Vue 2 components

14,643 2
vite-plugin-vue-svg

Import SVG files as Vue Components

7,149 104
@vitejs/plugin-vue

The official plugin for Vue SFC support in Vite.

333,357,380 686
vite-plugin-checker

Vite plugin that runs TypeScript type checker on a separate process.

133,975,562 1,242

Version History

Version Released Vue License
5.1.3 >=3.2.13 MIT
5.1.2 >=3.2.13 MIT
5.1.1 >=3.2.13 MIT
5.1.0 >=3.2.13 MIT
5.0.1 >=3.2.13 MIT