u
This commit is contained in:
1 parent
0f1604c709
commit
4e42a01b97
18 files changed
+1371
-47
No files matched your search
@@ -0,0 +1,34 @@
|
||||
import IconsResolver from 'unplugin-icons/resolver'
|
||||
import Components from 'unplugin-vue-components/vite'
|
||||
import { ArcoResolver } from 'unplugin-vue-components/resolvers'
|
||||
import type { PluginOption } from 'vite'
|
||||
|
||||
export function setupAutoImport(viteEnv: Env.ImportMeta) {
|
||||
// 从环境变量中提取图标相关的前缀
|
||||
const { VITE_ICON_PREFIX, VITE_ICON_LOCAL_PREFIX } = viteEnv
|
||||
|
||||
// 从本地图标前缀中提取图标集合名称
|
||||
const collectionName = VITE_ICON_LOCAL_PREFIX.replace(`${VITE_ICON_PREFIX}-`, '')
|
||||
const plugins: PluginOption[] = [
|
||||
Components({
|
||||
// 自动导入的组件类型声明文件
|
||||
dts: 'src/types/auto-import.d.ts',
|
||||
types: [
|
||||
{
|
||||
from: 'vue-router',
|
||||
names: ['RouterLink', 'RouterView'],
|
||||
},
|
||||
],
|
||||
|
||||
// 配置图标解析器
|
||||
resolvers: [
|
||||
IconsResolver({
|
||||
customCollections: [collectionName], // 本地图标集合
|
||||
componentPrefix: VITE_ICON_PREFIX, // 图标组件的前缀
|
||||
}),
|
||||
ArcoResolver(),
|
||||
],
|
||||
}),
|
||||
]
|
||||
return plugins
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import type { Plugin } from 'vite'
|
||||
|
||||
export function setupHtmlPlugin(buildTime: string) {
|
||||
const plugin: Plugin = {
|
||||
name: 'html-plugin',
|
||||
apply: 'build',
|
||||
transformIndexHtml(html) {
|
||||
return html.replace('<head>', `<head>\n <meta name="buildTime" content="${buildTime}">`)
|
||||
},
|
||||
}
|
||||
|
||||
return plugin
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import type { PluginOption } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
import VueDevtools from 'vite-plugin-vue-devtools'
|
||||
import progress from 'vite-plugin-progress'
|
||||
import { setupUnocss } from './unocss'
|
||||
import { setupHtmlPlugin } from './html'
|
||||
import { setupUnPluginIcon } from './unplugin-icon'
|
||||
import { setupAutoImport } from './auto-import'
|
||||
|
||||
export function setupVitePlugins(viteEnv: Env.ImportMeta, buildTime: string) {
|
||||
const plugins: PluginOption = [
|
||||
vue(),
|
||||
VueDevtools(),
|
||||
progress(),
|
||||
setupUnocss(viteEnv),
|
||||
setupHtmlPlugin(buildTime),
|
||||
setupAutoImport(viteEnv),
|
||||
...setupUnPluginIcon(viteEnv),
|
||||
]
|
||||
|
||||
return plugins
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import process from 'node:process'
|
||||
import path from 'node:path'
|
||||
import unocss from '@unocss/vite'
|
||||
import presetIcons from '@unocss/preset-icons'
|
||||
import { FileSystemIconLoader } from '@iconify/utils/lib/loader/node-loaders'
|
||||
|
||||
export function setupUnocss(viteEnv: Env.ImportMeta) {
|
||||
const { VITE_ICON_PREFIX, VITE_ICON_LOCAL_PREFIX } = viteEnv
|
||||
|
||||
const localIconPath = path.join(process.cwd(), 'src/assets/svg-icon')
|
||||
|
||||
/** The name of the local icon collection */
|
||||
const collectionName = VITE_ICON_LOCAL_PREFIX.replace(`${VITE_ICON_PREFIX}-`, '')
|
||||
|
||||
return unocss({
|
||||
presets: [
|
||||
presetIcons({
|
||||
prefix: `${VITE_ICON_PREFIX}-`,
|
||||
scale: 1,
|
||||
extraProperties: {
|
||||
display: 'inline-block',
|
||||
},
|
||||
collections: {
|
||||
[collectionName]: FileSystemIconLoader(localIconPath, (svg) =>
|
||||
svg.replace(/^<svg\s/, '<svg width="1em" height="1em" '),
|
||||
),
|
||||
},
|
||||
warn: true,
|
||||
}),
|
||||
],
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import path from 'node:path'
|
||||
import process from 'node:process'
|
||||
import { FileSystemIconLoader } from 'unplugin-icons/loaders'
|
||||
import type { PluginOption } from 'vite'
|
||||
import Icons from 'unplugin-icons/vite'
|
||||
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
|
||||
export function setupUnPluginIcon(viteEnv: Env.ImportMeta) {
|
||||
const { VITE_ICON_PREFIX, VITE_ICON_LOCAL_PREFIX } = viteEnv
|
||||
|
||||
const localIconPath = path.join(process.cwd(), 'src/assets/svg-icon')
|
||||
/** The name of the local icon collection */
|
||||
const collectionName = VITE_ICON_LOCAL_PREFIX.replace(`${VITE_ICON_PREFIX}-`, '')
|
||||
|
||||
const plugins: PluginOption[] = [
|
||||
createSvgIconsPlugin({
|
||||
iconDirs: [localIconPath],
|
||||
symbolId: `${VITE_ICON_LOCAL_PREFIX}-[dir]-[name]`,
|
||||
inject: 'body-last',
|
||||
customDomId: '__SVG_ICON_LOCAL__',
|
||||
}),
|
||||
Icons({
|
||||
compiler: 'vue3',
|
||||
customCollections: {
|
||||
[collectionName]: FileSystemIconLoader(localIconPath, (svg) =>
|
||||
svg.replace(/^<svg\s/, '<svg width="1em" height="1em" '),
|
||||
),
|
||||
},
|
||||
scale: 1,
|
||||
defaultClass: 'inline-block',
|
||||
}),
|
||||
]
|
||||
|
||||
return plugins
|
||||
}
|
||||
Reference in new issue
Block a user