unplugin-svg-vue-component

Use svg as vue components with support for both vue2.7 and vue3.x
953,115 3
Install
npm install unplugin-svg-vue-component
Latest Version:0.1.1
Older releases:2 · 3
License:MIT
Last Updated:Nov 4, 2023
Links: GitHub  ·  npm
Maintainer: jaw52

unplugin-svg-vue-component

GitHub package.json version

Use SVG as vue components with support for both vue2.7 and vue3.x.

npm i -D unplugin-svg-vue-component

Usage

Vite

import svgPlugin from 'unplugin-svg-vue-component/vite'
import vue from '@vitejs/plugin-vue'
import { defineConfig } from 'vite'

export default defineConfig({
  plugins: [
    vue(),
    svgPlugin(),
  ],
})
<script setup lang="ts">
import MsgIcon from './msg.svg'

// OR
// import MsgIcon from './msg.svg?component'
</script>

<template>
  <MsgIcon />
</template>

Options

  • optimize: Disabled by default. Based on svgo
// https://github.com/svg/svgo
export default defineConfig({
  plugins: [
    vue2(),
    svgPlugin({ optimize: true }),
  ],
})

Used in TypeScript

First tsconfig configuration

{
  "compilerOptions": {
    "types": ["unplugin-svg-vue-component/client"]
  }
}

Then import the SVG using the following form to avoid ts errors

import MsgIcon from './msg.svg?component'

Acknowledgement

Integration of the following schemes

License

MIT

Related Packages

vite-plugin-vue2-svg

load SVG files as Vue components, for Vue2.x only.

345,822 19
@kingyue/vite-plugin-vue2-svg

Vite plugin to load SVG files as Vue 2 components

14,643 2
vite-plugin-vue2

Vite plugin for Vue2

1,474,659 618
vite-plugin-git-revision

Vite plugin that generates VERSION and COMMITHASH files during build based on a...

21,961 11
@koala/yibin-ui

宜宾大脑主题定制

4,077

Version History

Version Released License
0.1.1 MIT
0.1.0 MIT
0.0.5 MIT
0.0.4 MIT
0.0.3 MIT
Pre-releases (9)
Version Released License
0.1.1-beta.0 MIT
0.1.0-beta.1 MIT
0.1.0-beta.0 MIT
0.0.5-beta.2 MIT
0.0.5-beta.1 MIT