From ee834399c053a03f424c619753a010f6fd93bfe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=9D=E5=85=88=E7=91=9E?= <1490493387@qq.com> Date: Sat, 2 Apr 2022 23:51:14 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E5=8D=87=E7=BA=A7vite-plugin-svg-icon?= =?UTF-8?q?s=E7=89=88=E6=9C=AC=E8=87=B32.0.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 ++- src/main.ts | 1 + tsconfig.json | 1 + vite.config.ts | 10 +++++----- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 5898d86c..0ad399a0 100644 --- a/package.json +++ b/package.json @@ -29,10 +29,11 @@ "@types/nprogress": "^0.2.0", "@types/path-browserify": "^1.0.0", "@vitejs/plugin-vue": "^1.9.3", + "fast-glob": "^3.2.11", "sass": "^1.43.4", "typescript": "^4.4.3", "vite": "^2.6.4", - "vite-plugin-svg-icons": "^1.1.0", + "vite-plugin-svg-icons": "^2.0.1", "vue-tsc": "^0.3.0" } } diff --git a/src/main.ts b/src/main.ts index 8046f46b..e5c254a1 100644 --- a/src/main.ts +++ b/src/main.ts @@ -10,6 +10,7 @@ import 'element-plus/theme-chalk/index.css' import Pagination from '@/components/Pagination/index.vue' import '@/permission' +// 引入svg注册脚本 import 'virtual:svg-icons-register'; // 国际化 diff --git a/tsconfig.json b/tsconfig.json index 31bd024e..1b976aaf 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -16,6 +16,7 @@ }, "allowSyntheticDefaultImports": true, // 默认导入 "skipLibCheck": true, // 不对第三方依赖类型检查 ,element-plus 生产打包报错 + "types": ["vite-plugin-svg-icons/client"] }, "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"] } diff --git a/vite.config.ts b/vite.config.ts index e8d53162..3a27aada 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,10 +1,10 @@ -import {UserConfig, ConfigEnv, loadEnv} from 'vite' +import { UserConfig, ConfigEnv, loadEnv } from 'vite' import vue from '@vitejs/plugin-vue' -import viteSvgIcons from 'vite-plugin-svg-icons'; +import { createSvgIconsPlugin } from 'vite-plugin-svg-icons' import path from 'path' // @see: https://gitee.com/holysheng/vite2-config-description/blob/master/vite.config.ts -export default ({command, mode}: ConfigEnv): UserConfig => { +export default ({ command, mode }: ConfigEnv): UserConfig => { // 获取 .env 环境配置文件 const env = loadEnv(mode, process.cwd()) @@ -12,11 +12,11 @@ export default ({command, mode}: ConfigEnv): UserConfig => { { plugins: [ vue(), - viteSvgIcons({ + createSvgIconsPlugin({ // 指定需要缓存的图标文件夹 iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')], // 指定symbolId格式 - symbolId: 'icon-[dir]-[name]', + symbolId: 'icon-[dir]-[name]' }) ],