@kingyue/vite-plugin-vue2-svg

Vite plugin to load SVG files as Vue 2 components
14,643 2
Install
npm install @kingyue/vite-plugin-vue2-svg
Latest Version:0.6.0
Vue:2
License:MIT
Last Updated:Jul 13, 2023
Links: GitHub  ·  npm
Maintainer: kingyue

vite-plugin-vue2-svg

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

This fork fixs bugs of the unmaintained original repo.

NPM

Install

pnpm add -D @kingyue/vite-plugin-vue2-svg
# or
yarn add -D @kingyue/vite-plugin-vue2-svg
# or
npm install -D @kingyue/vite-plugin-vue2-svg

Usage

// vite.config.ts
import { defineConfig } from "vite";
import createVuePlugin from "@vitejs/plugin-vue2";
import { createSvgPlugin } from "@kingyue/vite-plugin-vue2-svg";

export default defineConfig({
  plugins: [createVuePlugin(), createSvgPlugin()],
});
<!-- App.vue -->
<template>
  <Icon />
</template>
<script>
import Icon from "./icon.svg";

export default {
  components: {
    Icon,
  },
};
</script>

If you want disabled this plugin for specific file, just add ?raw when you import.

import Icon from "./icon.svg?raw"; // svg file import without transform

Options

createSvgPlugin(option: {
  svgo?: boolean            // whether optimized by svgo
  svgoConfig?: SVGO.Options // check https://github.com/svg/svgo
  defaultImport?: 'url' | 'raw'
} = {});

License

MIT

Related Packages

vite-svg-loader

Vite plugin to load SVG files as Vue components

28,813,015 701
@anyone-dev/vite-svg-loader

Vite plugin to load SVG files as Vue components

28,465 701
vite-plugin-vue2-svg

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

345,822 19
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

Version History

Version Released Vue License
0.6.0 ^2.7.14 MIT
0.5.0 ^2.7.14 MIT
0.4.0 ^2.7.14 MIT