vite-plugin-vue2-svg
Load SVG files as Vue components, for Vue2.x only.
This fork fixs bugs of the unmaintained original repo.
Install
pnpm add -D @kingyue/vite-plugin-vue2-svg
yarn add -D @kingyue/vite-plugin-vue2-svg
npm install -D @kingyue/vite-plugin-vue2-svg
Usage
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";
Options
createSvgPlugin(option: {
svgo?: boolean
svgoConfig?: SVGO.Options
defaultImport?: 'url' | 'raw'
} = {});
License
MIT