Current collected state Current
Observed since 20 Oct, 22:16 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
generate a vue/react component through svg files, supporting svg file HMR and typescript intelligence prompt.
English | 中文
unplugin-svg-component inspired by vite-plugin-svg-icons, it will generate a Vue/React component through SVG files, use the SVG icon through the component.


yarn add unplugin-svg-component -D
# or
npm i unplugin-svg-component -D
# or
pnpm install unplugin-svg-component -D
// vite.config.ts
import { defineConfig } from 'vite'
import UnpluginSvgComponent from 'unplugin-svg-component/vite'
export default defineConfig({
plugins: [
UnpluginSvgComponent({ /* options */ }),
],
})
// vue.config.js
const { defineConfig } = require('@vue/cli-service')
const UnpluginSvgComponent = require('unplugin-svg-component/webpack').default
module.exports = defineConfig({
configureWebpack: {
plugins: [
UnpluginSvgComponent({ /* options */ })
]
}
})
// webpack.config.js
const UnpluginSvgComponent = require('unplugin-svg-component/webpack').default
module.exports = {
/* ... */
plugins: [
UnpluginSvgComponent({ /* options */ }),
],
}
// rollup.config.js
import UnpluginSvgComponent from 'unplugin-svg-component/rollup'
export default {
plugins: [
UnpluginSvgComponent({ /* options */ }),
],
}
// esbuild.config.js
import { build } from 'esbuild'
import UnpluginSvgComponent from 'unplugin-svg-component/esbuild'
build({
/* ... */
plugins: [
UnpluginSvgComponent({
/* options */
}),
],
})
// main.ts
import SvgIcon from '~virtual/svg-component'
app.component(SvgIcon.name, SvgIcon)
// App.tsx
import SvgIcon from '~virtual/svg-component'
function App() {
return (
<div className="logo">
<SvgIcon name='icon-react'></SvgIcon>
</div>
)
}
| Parameter | Type | Default | Description |
|---|---|---|---|
| iconDir | string | - | the icon folder of the Sprite image |
| projectType | vue | react | auto | auto | the project type, detect automatically |
| dts | boolean | - | whether generate d.ts file |
| dtsDir | string | - | d.ts location |
| prefix | string | - | symbolId prefix |
| componentName | string | SvgIcon | the name of component |
| componentStyle | string | width: 1em; height: 1em; fill:currentColor; | the style of component |
| preserveColor | RegExp | - | usually, the plugin will set SVG's fill and stroke with 'currentColor', this option will perform regular matching on each SVG path, the successfully matched SVG will not do the replacement, but retain the original color. |
| symbolIdFormatter | (svgName:string, prefix: string)=>string | look this way | the symbolId's formatter |
| optimizeOptions | SvgoOptions | - | svgo optimize Options |
| svgSpriteDomId | string | svg_sprite__dom | Customize the ID of the svgDom |
| vueVersion | 2 | 3 | auto | auto | Vue version |
| scanGlob | string[] | look this way | the glob pattern used in tree-shaking |
// tsconfig.json
{
"include": ["svg-component.d.ts", "svg-component-global.d.ts"]
}
You can refer to examples as required. Note that the configuration in examples is the default configuration.
git checkout -b feature/fooBar)git commit -am 'Add some fooBar')git push origin feature/fooBar)MIT License © 2022-PRESENT Jevon617
Download counts and popularity will appear here as the collector receives them.
| Version | Published | Direct dependencies | Open version |
|---|---|---|---|
| 0.5.1Registry latest | 17 Mar 2023 | 23 |
This describes our collected data; it is not a security assessment.
Shared repository data · GitHub
Observed since 20 Oct, 22:16 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:6ef39616bfb856c6a54b2ad535ecabbb2daae2e2959f98470358fc9e22704a1b