Skip to content

Vite 2.x plugin to load SVG files as Vue components

License

Notifications You must be signed in to change notification settings

Miguelklappes/vite-svg-loader

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vite SVG loader

Vite 2.x 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 {
  plugins: [vue(), svgLoader()]
}

SVGO Configuration

vite.config.js

svgLoader({
  svgoConfig: {
    multipass: true
  }
})

Disable SVGO

vite.config.js

svgLoader({
  svgo: false
})

Use with TypeScript

If you use the loader in a Typescript project, you'll need to import your svg files with the ?component param: import MyIcon from './my-icon.svg?component'. You'll also need to add the type definitions to src/vite-env.d.ts:

src/vite-env.d.ts

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

About

Vite 2.x plugin to load SVG files as Vue components

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%