Gathering detailed insights and metrics for vite-plugin-svg-icons
Gathering detailed insights and metrics for vite-plugin-svg-icons
Gathering detailed insights and metrics for vite-plugin-svg-icons
Gathering detailed insights and metrics for vite-plugin-svg-icons
vite-plugin-svg-icons-ng
Vite plugin for easily creating an SVG sprite and injecting it for use, with a brand-new version.
@digitalacorn/vite-plugin-svg-icons
Vite Plugin for fast creating SVG sprites.
vite-plugin-svg-spritemap
Generates a SVG spritemap from multiple .svg files
vite-plugin-svgs-icons
vite-plugin-svgs-icons svg-icon svg icon MultiColor修改
npm install vite-plugin-svg-icons
Typescript
Module System
Node Version
NPM Version
63.5
Supply Chain
45.3
Quality
68.3
Maintenance
50
Vulnerability
98.2
License
TypeScript (84.95%)
Vue (8.89%)
Shell (3.72%)
HTML (2.45%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
887 Stars
74 Commits
121 Forks
4 Watchers
1 Branches
10 Contributors
Updated on May 05, 2025
Minified
Minified + Gzipped
Latest Version
2.0.1
Package Id
vite-plugin-svg-icons@2.0.1
Unpacked Size
18.90 kB
Size
4.58 kB
File Count
6
NPM Version
8.1.2
Node Version
16.13.2
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
5
English | 中文
Used to generate svg sprite map.
node version: >=12.0.0
vite version: >=2.0.0
1yarn add vite-plugin-svg-icons -D 2# or 3npm i vite-plugin-svg-icons -D 4# or 5pnpm install vite-plugin-svg-icons -D
1import { createSvgIconsPlugin } from 'vite-plugin-svg-icons' 2import path from 'path' 3 4export default () => { 5 return { 6 plugins: [ 7 createSvgIconsPlugin({ 8 // Specify the icon folder to be cached 9 iconDirs: [path.resolve(process.cwd(), 'src/icons')], 10 // Specify symbolId format 11 symbolId: 'icon-[dir]-[name]', 12 13 /** 14 * custom insert position 15 * @default: body-last 16 */ 17 inject?: 'body-last' | 'body-first' 18 19 /** 20 * custom dom id 21 * @default: __svg__icons__dom__ 22 */ 23 customDomId: '__svg__icons__dom__', 24 }), 25 ], 26 } 27} 28
1import 'virtual:svg-icons-register'
Here the svg sprite map has been generated
/src/components/SvgIcon.vue
1<template> 2 <svg aria-hidden="true"> 3 <use :href="symbolId" :fill="color" /> 4 </svg> 5</template> 6 7<script> 8import { defineComponent, computed } from 'vue' 9 10export default defineComponent({ 11 name: 'SvgIcon', 12 props: { 13 prefix: { 14 type: String, 15 default: 'icon', 16 }, 17 name: { 18 type: String, 19 required: true, 20 }, 21 color: { 22 type: String, 23 default: '#333', 24 }, 25 }, 26 setup(props) { 27 const symbolId = computed(() => `#${props.prefix}-${props.name}`) 28 return { symbolId } 29 }, 30}) 31</script>
1# src/icons 2 3- icon1.svg 4- icon2.svg 5- icon3.svg 6- dir/icon1.svg
/src/App.vue
1<template> 2 <div> 3 <SvgIcon name="icon1"></SvgIcon> 4 <SvgIcon name="icon2"></SvgIcon> 5 <SvgIcon name="icon3"></SvgIcon> 6 <SvgIcon name="dir-icon1"></SvgIcon> 7 </div> 8</template> 9 10<script> 11import { defineComponent, computed } from 'vue' 12 13import SvgIcon from './components/SvgIcon.vue' 14export default defineComponent({ 15 name: 'App', 16 components: { SvgIcon }, 17}) 18</script>
/src/components/SvgIcon.jsx
1export default function SvgIcon({
2 name,
3 prefix = 'icon',
4 color = '#333',
5 ...props
6}) {
7 const symbolId = `#${prefix}-${name}`
8
9 return (
10 <svg {...props} aria-hidden="true">
11 <use href={symbolId} fill={color} />
12 </svg>
13 )
14}
1# src/icons 2 3- icon1.svg 4- icon2.svg 5- icon3.svg 6- dir/icon1.svg
/src/App.jsx
1import SvgIcon from './components/SvgIcon' 2 3export default function App() { 4 return ( 5 <> 6 <SvgIcon name="icon1"></SvgIcon> 7 <SvgIcon name="icon1"></SvgIcon> 8 <SvgIcon name="icon1"></SvgIcon> 9 <SvgIcon name="dir-icon1"></SvgIcon> 10 </> 11 ) 12}
1import ids from 'virtual:svg-icons-names' 2// => ['icon-icon1','icon-icon2','icon-icon3']
Parameter | Type | Default | Description |
---|---|---|---|
iconDirs | string[] | - | Need to generate the icon folder of the Sprite image |
symbolId | string | icon-[dir]-[name] | svg symbolId format, see the description below |
svgoOptions | boolean|SvgoOptions | true | svg compression configuration, can be an objectOptions |
inject | string | body-last | svgDom default insertion position, optional body-first |
customDomId | string | __svg__icons__dom__ | Customize the ID of the svgDom insert node |
symbolId
icon-[dir]-[name]
[name]:
svg file name
[dir]
The svg of the plug-in will not generate hash to distinguish, but distinguish it by folder.
If the folder corresponding to iconDirs
contains this other folder
example:
Then the generated SymbolId is written in the comment
1# src/icons 2- icon1.svg # icon-icon1 3- icon2.svg # icon-icon2 4- icon3.svg # icon-icon3 5- dir/icon1.svg # icon-dir-icon1 6- dir/dir2/icon1.svg # icon-dir-dir2-icon1
If using Typescript
, you can add in tsconfig.json
1// tsconfig.json 2{ 3 "compilerOptions": { 4 "types": ["vite-plugin-svg-icons/client"] 5 } 6}
Note
Although the use of folders to distinguish between them can largely avoid the problem of duplicate names, there will also be svgs with multiple folders and the same file name in iconDirs
.
This needs to be avoided by the developer himself
Run
1 2pnpm install 3cd ./packages/playground/basic 4pnpm run dev 5pnpm run build 6
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 6/23 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
38 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-05-05
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More