import path from 'node:path' import unpluginViteComponents from 'unplugin-vue-components/vite' // 自动按需导入 import vueI18nPlugin from '@intlify/unplugin-vue-i18n/vite' // i18n import { createSvgIconsPlugin } from 'vite-plugin-svg-icons' // `svg icon` import type { ComponentResolver, TypeImport } from 'unplugin-vue-components' import type { BuildOptions } from 'vite' import type { ViteSvgIconsPlugin } from 'vite-plugin-svg-icons' /** * * @param options `svg icon` 自定义配置 * * 使用 `svg` 作为图标 */ export const viteSVGIcon = (options?: ViteSvgIconsPlugin) => { const defaultOptions = { iconDirs: [path.resolve(process.cwd(), 'src/icons')], symbolId: 'icon-[dir]-[name]', inject: 'body-last', customDomId: '__svg__icons__dom__', } return createSvgIconsPlugin(Object.assign({}, defaultOptions, options)) } /** * * @param resolvers 按需加载依赖项 * @param types 按需加载依赖类型 * * 按需加载 */ export const viteComponents = async ( resolvers: (ComponentResolver | ComponentResolver[])[] = [], types: TypeImport[] = [], ) => unpluginViteComponents({ dts: './unplugin/components.d.ts', resolvers: [...resolvers], types: [ { from: 'vue-router', names: ['RouterLink', 'RouterView'], }, ...types, ], }) export const viteVueI18nPlugin = () => vueI18nPlugin({ runtimeOnly: true, compositionOnly: true, forceStringify: true, defaultSFCLang: 'json', include: [path.resolve(__dirname, '../locales/**')], }) /** * * @param title 浏览器 title 名称 */ export const HTMLTitlePlugin = (title: string) => { return { name: 'html-transform', transformIndexHtml: (html: string) => { return html.replace(/