Gathering detailed insights and metrics for vite-plugin-vue-element-plug-icon
Gathering detailed insights and metrics for vite-plugin-vue-element-plug-icon
Gathering detailed insights and metrics for vite-plugin-vue-element-plug-icon
Gathering detailed insights and metrics for vite-plugin-vue-element-plug-icon
npm install vite-plugin-vue-element-plug-icon
Typescript
Module System
Min. Node Version
Node Version
NPM Version
38.1
Supply Chain
88.9
Quality
74.7
Maintenance
50
Vulnerability
98.2
License
TypeScript (92.87%)
JavaScript (7.13%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
631
Last Day
1
Last Week
2
Last Month
17
Last Year
129
MIT License
2 Stars
25 Commits
2 Watchers
7 Branches
1 Contributors
Updated on Sep 08, 2023
Latest Version
1.0.3
Package Id
vite-plugin-vue-element-plug-icon@1.0.3
Unpacked Size
13.14 kB
Size
3.92 kB
File Count
9
NPM Version
8.15.0
Node Version
16.17.1
Cumulative downloads
Total Downloads
Last Day
0%
1
Compared to previous day
Last Week
0%
2
Compared to previous week
Last Month
142.9%
17
Compared to previous month
Last Year
-4.4%
129
Compared to previous year
a vite plugin to load svg icon for element-plug
Importing a svg file, you would get a url of file in vite
In most cases, we want a Vue component to render in page directly.
In element-plus, it supply a el-icon
Element, and a built-in Svg resource library
Use your svg file, it`s not render properly, such as not supporting color attribute
So I create thie vite plugin to svg file, import as vue component, and optimize using for element-plug icon
1// pnpm 2pnpm add vite-plugin-vue-element-plug-icon -D 3 4// npm 5npm install vite-plugin-vue-element-plug-icon -D 6 7// yarn 8yarn add vite-plugin-vue-element-plug-icon --D
vite.config.ts
1import vpvepi from 'vite-plugin-vue-element-plug-icon' 2 3export default defineConfig({ 4 plugins: [vpvepi()], 5})
1<script setup lang="ts"> 2import Coffee from './coffee.svg' 3import CoffeeRaw from './coffee.svg?raw' 4import CoffeeUrl from './coffee.svg?url' 5</script> 6<template> 7 <div> 8 <!-- used in element-plus, support color, size attrs and etc --> 9 <el-icon color="red" class="is-loading" :size="100"> 10 <Coffee /> 11 </el-icon> 12 </div> 13 <div> 14 <CoffeeRaw /> 15 </div> 16 <div> 17 {{ CoffeeUrl }} 18 </div> 19</template>
default value
svg file will be imported as Vue component, with optimized for element-plus
1import CoffeeComp from './coffee.svg?component' 2// <CoffeeComp />
svg file will be imported as Vue component, without optimized for element-plus
1import CoffeeRaw from './coffee.svg?raw' 2// <CoffeeRaw />
svg file will be imported as file path
1import CoffeeUrl from './coffee.svg?url' 2// {{ CoffeeUrl }}
1import vpvepi from 'vite-plugin-vue-element-plug-icon' 2 3export default defineConfig({ 4 plugins: [ 5 vpvepi({ 6 defaultQuery: 'raw', // component(default value), url, raw 7 }), 8 ], 9})
1import vpvepi from 'vite-plugin-vue-element-plug-icon' 2 3export default defineConfig({ 4 plugins: [ 5 vpvepi({ 6 svgoConfig(path) { 7 // svgo config options 8 return { 9 multipass: true, 10 } 11 }, 12 }), 13 ], 14})
use getDefaultSvgoOptions
to get default svgo options, you can merge options from the return value
1import vpvepi, { getDefaultSvgoOptions } from 'vite-plugin-vue-element-plug-icon' 2 3export default defineConfig({ 4 plugins: [ 5 vpvepi({ 6 svgoConfig(path) { 7 // svgo config options 8 const ops = getDefaultSvgoOptions(path) 9 return { 10 ...ops, 11 multipass: false, 12 } 13 }, 14 }), 15 ], 16})
you can use svg plugin svgo-plugin-replace-fill
separately
it would replace fill
attr directly
1import sprf from 'vite-plugin-vue-element-plug-icon/dist/svgo-plugin-replace-fill.cjs' 2 3vpvepi({ 4 svgoConfig() { 5 return { 6 plugins: [sprf], 7 } 8 }, 9}),
No vulnerabilities found.
No security vulnerabilities found.