0.1.7 • Published 2 months ago

@devotee/svgtovue v0.1.7

Weekly downloads
-
License
ISC
Repository
-
Last release
2 months ago

vite-plugin-svgtovue

一个将 SVG 文件转化为 Vue 组件的插件,支持 vue, jsx, tsx 三种格式。子文件夹下的 color 直接转化为组件,不处理 path,polygon,circle 等中的属性

代码演示:
import pathe from 'node:path'
import svgComponent from 'vite-plugin-svgtovue'
import { defineConfig } from 'vite'

export default defineConfig({
  plugins: [
    svgComponent({
      input: pathe.join(__dirname, '../wwwsvg/'),
      output: './src/components/tri-icon/',
      suffix: 'ts',
      template: 'tsx',
      outputListPath: './src/components/tri-icon/list.ts',
    }),
  ],
})
const path = require('path')
const { defineConfig } = require('@vue/cli-service')
const WebpackSvgComponent = require('../../dist/webpack.cjs')

const svgComponents = new WebpackSvgComponent({
  input: path.join(__dirname, '../wwwsvg/'),
  output: './src/components/iconfont/',
  suffix: 'ts',
  template: 'vue3',
  outputListPath: './src/components/iconfont/list.ts',
})

module.exports = defineConfig({
  transpileDependencies: true,
  configureWebpack: (config) => {
    const plugins = [svgComponents]
    config.plugins = [...config.plugins, ...plugins]
  },
})
生成代码目录
tri-icon 目录:
├─── src // 组件目录
├─── index.html // 演示 demo,展示列表
├─── index.ts  
 ├─── list.ts // SVG 列表,一般用于展示所有 SVG 图标
插件参数列表
参数名称参数描述参数值默认值
inputSVG 文件位置string必须
output组件输出位置string必须
prefix组件前缀stringtri
suffix组件导出前缀js, tsts
template生成 vue 组件的模版vue2,tsx,jsxvue3
templatePath自定义 vue 组件的模版string----
outputDemoPathdemo 的输出路径string----
outputListPath列表的输出路径string----
组件引入使用
  1. 全局导入

    import { createApp } from 'vue'
    import App from './App.vue'
    import TriIcon from './components/tri-icon'
    
    createApp(App).use(TriIcon).mount('#app')
  2. 局部引用

    <script setup lang="ts">
    import TriUser from './components/tri-icon/src/TriUser.vue'
    </script>
    
    <template>
      <div class="tri-icon">
        <tri-icon size="28px" color="var(--color-white)" />
      </div>
    </template>
0.1.7

2 months ago

0.1.2

3 months ago

0.1.3

3 months ago

0.1.6

3 months ago

0.1.5

3 months ago

0.1.1

3 months ago