vite-plugin-svg
Use SVG files as Vue Components
36,058
104
| Install | |
|---|---|
npm install vite-plugin-svg |
|
| Latest Version: | 0.7.0 |
| License: | MIT |
| Last Updated: | Mar 4, 2023 |
| Links: | GitHub · npm |
Maintainer: visualfanatic
Features:
- SVGO optimization
- Hot Module Replacement support
- Default SVG import behavior support
Currently supported Vite version:
Install
yarn add --dev vite-plugin-svg
npm i -D vite-plugin-svg
Usage
Starting from v0.4.0 to use SVG file as a component, just import VueComponent from the path of the file.
This gives you more control over how a particular SVG file should be loaded and processed:
// Get URL to SVG file
import myIconUrl from './svgs/my-icon.svg';
const img = document.createElement('img');
img.src = myIconUrl;
.my-icon {
/* Get URL to SVG file */
background-image: url("./svgs/my-icon.svg");
}
<template>
<div>
<MyIcon />
</div>
</template>
<script>
import { VueComponent as MyIcon } from './svgs/my-icon.svg';
export default {
components: {
MyIcon,
},
};
</script>
Setup
vite.config.js
const svgPlugin = require('vite-plugin-svg');
module.exports = {
plugins: [
svgPlugin(),
],
};
TODO:
- Convert plugin to TS
- Support disabling SVGO
- Basic test coverage
Related Packages
laravel-mix-svg-vue
A Laravel Mix extension to inline SVG files with Vue.js and automatically optimi...
76,655
38
vite-plugin-svg4vue
A vite plugin which can transform svg icon to vue component, support optimizatio...
30,543
23
Version History
| Version | Released | License |
|---|---|---|
| 0.7.0 | MIT | |
| 0.6.0 | MIT | |
| 0.5.0 | MIT | |
| 0.4.1 | MIT | |
| 0.4.0 | MIT | |
| 0.3.1 | MIT | |
| 0.3.0 | MIT | |
| 0.2.0 | MIT | |
| 0.1.1 | MIT |