You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
230 lines
6.2 KiB
230 lines
6.2 KiB
import { resolve } from 'path'
|
|
import Vue from '@vitejs/plugin-vue'
|
|
import VueJsx from '@vitejs/plugin-vue-jsx'
|
|
import progress from 'vite-plugin-progress'
|
|
import EslintPlugin from 'vite-plugin-eslint'
|
|
import PurgeIcons from 'vite-plugin-purge-icons'
|
|
// import { visualizer } from 'rollup-plugin-visualizer'
|
|
|
|
import { ViteEjsPlugin } from 'vite-plugin-ejs'
|
|
// @ts-ignore
|
|
import ElementPlus from 'unplugin-element-plus/vite'
|
|
import AutoImport from 'unplugin-auto-import/vite'
|
|
import Components from 'unplugin-vue-components/vite'
|
|
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
|
|
import viteCompression from 'vite-plugin-compression'
|
|
import topLevelAwait from 'vite-plugin-top-level-await'
|
|
import VueI18nPlugin from '@intlify/unplugin-vue-i18n/vite'
|
|
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons-ng'
|
|
|
|
import { IconJson } from '../../src/components/Icon/src/data.ts'
|
|
|
|
import UnoCSS from 'unocss/vite'
|
|
|
|
const preloadOfflineIcons = (iconData: Record<string, string[]>): string[] => {
|
|
return Object.entries(iconData).reduce((a: string[], [k, v]) => {
|
|
a = a.concat(v.map((i) => k + i))
|
|
return a
|
|
}, [])
|
|
}
|
|
const offlineIcons = [
|
|
"fa:stack-exchange",
|
|
"fa:leanpub",
|
|
"ep:house",
|
|
"fa-solid:house-user",
|
|
"fa:bars",
|
|
"fa-solid:file-signature",
|
|
"fa:hdd-o",
|
|
"fa:universal-access",
|
|
"fa:tag",
|
|
"fa:edit",
|
|
"fa:archive",
|
|
"fa:edit",
|
|
"fa-solid:grin-stars",
|
|
"ep:guide",
|
|
"ep:document",
|
|
"fa:address-book",
|
|
"ep:avatar",
|
|
"fa-solid:box",
|
|
"ep:document-copy",
|
|
"ep:position",
|
|
"ep:aim",
|
|
"ep:place",
|
|
"ep:message",
|
|
"ep:connection",
|
|
"fa-solid:project-diagram",
|
|
"fa-solid:book",
|
|
"ep:data-analysis",
|
|
"ep:trend-charts",
|
|
"ep:set-up",
|
|
"ep:bicycle",
|
|
"ep:notebook",
|
|
"ep:link",
|
|
"ep:home-filled",
|
|
"fa:y-combinator",
|
|
"ep:iphone",
|
|
"fa-solid:smog",
|
|
"ep:bell",
|
|
"ep:connection",
|
|
"ep:user",
|
|
"fa:key",
|
|
"fa:reddit-square",
|
|
"fa:wpforms",
|
|
"ep:promotion",
|
|
"ep:warning-filled",
|
|
"fa:edit",
|
|
"fa:hdd-o",
|
|
"fa-solid:mail-bulk",
|
|
"fa:area-chart",
|
|
"ep:avatar",
|
|
"fa:tree",
|
|
"ep:platform",
|
|
"fa-solid:tools",
|
|
"ep:mostly-cloudy",
|
|
"fa:cog",
|
|
"fa:square-o",
|
|
"ep:bell-filled",
|
|
"ep:menu",
|
|
"ep:coffee-cup",
|
|
"fa:fighter-jet",
|
|
"ep:message-box",
|
|
"fa:object-ungroup",
|
|
"fa-solid:layer-group",
|
|
"fa-solid:cogs",
|
|
"ep:calendar",
|
|
"ep:operation",
|
|
"fa:battery-1",
|
|
"fa:address-card",
|
|
"ep:takeaway-box",
|
|
"fa:eye",
|
|
"fa:tasks",
|
|
"fa:user-secret",
|
|
"fa:mobile",
|
|
"ep:histogram",
|
|
"fa:exclamation-triangle",
|
|
"fa:address-book-o",
|
|
"ep:upload-filled",
|
|
"ep:connection",
|
|
"fa:assistive-listening-systems",
|
|
"ep:folder-opened",
|
|
"ep:management",
|
|
"ep:document-copy",
|
|
"ep:collection",
|
|
"ep:files",
|
|
"fa:wpexplorer",
|
|
"fa-solid:tasks",
|
|
"ep:chat-dot-round",
|
|
"fa:connectdevelop",
|
|
"ep:document-copy",
|
|
"ep:tools",
|
|
"fa:dedent",
|
|
"fa:slack",
|
|
"fa:dashcube",
|
|
"fa:rocket",
|
|
"fa:battery-3",
|
|
"fa:square",
|
|
"ep:monitor",
|
|
"ep:calendar",
|
|
"ep:collection-tag",
|
|
"fa:power-off",
|
|
"fa:map-marker",
|
|
"ep:monitor",
|
|
"fa:tasks",
|
|
"fa:delicious",
|
|
"ep:copy-document",
|
|
"fa:road",
|
|
"ep:pie-chart",
|
|
"fa:medium",
|
|
"fa-solid:hdd"
|
|
]
|
|
export function createVitePlugins() {
|
|
const root = process.cwd()
|
|
|
|
// 路径查找
|
|
function pathResolve(dir: string) {
|
|
return resolve(root, '.', dir)
|
|
}
|
|
|
|
return [
|
|
Vue(),
|
|
VueJsx(),
|
|
UnoCSS(),
|
|
progress(),
|
|
PurgeIcons({
|
|
//included: offlineIcons,//
|
|
included: preloadOfflineIcons(IconJson)
|
|
}),
|
|
ElementPlus({}),
|
|
AutoImport({
|
|
include: [
|
|
/\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
|
|
/\.vue$/,
|
|
/\.vue\?vue/, // .vue
|
|
/\.md$/ // .md
|
|
],
|
|
imports: [
|
|
'vue',
|
|
'vue-router',
|
|
// 可额外添加需要 autoImport 的组件
|
|
{
|
|
'@/hooks/web/useI18n': ['useI18n'],
|
|
'@/hooks/web/useMessage': ['useMessage'],
|
|
'@/hooks/web/useTable': ['useTable'],
|
|
'@/hooks/web/useCrudSchemas': ['useCrudSchemas'],
|
|
'@/utils/formRules': ['required'],
|
|
'@/utils/dict': ['DICT_TYPE']
|
|
}
|
|
],
|
|
dts: 'src/types/auto-imports.d.ts',
|
|
resolvers: [ElementPlusResolver()],
|
|
eslintrc: {
|
|
enabled: false, // Default `false`
|
|
filepath: './.eslintrc-auto-import.json', // Default `./.eslintrc-auto-import.json`
|
|
globalsPropValue: true // Default `true`, (true | false | 'readonly' | 'readable' | 'writable' | 'writeable')
|
|
}
|
|
}),
|
|
Components({
|
|
// 生成自定义 `auto-components.d.ts` 全局声明
|
|
dts: 'src/types/auto-components.d.ts',
|
|
// 自定义组件的解析器
|
|
resolvers: [ElementPlusResolver()],
|
|
globs: ['src/components/**/**.{vue, md}', '!src/components/DiyEditor/components/mobile/**']
|
|
}),
|
|
// EslintPlugin({
|
|
// cache: false,
|
|
// include: ['src/**/*.vue', 'src/**/*.ts', 'src/**/*.tsx'] // 检查的文件
|
|
// }),
|
|
VueI18nPlugin({
|
|
runtimeOnly: true,
|
|
compositionOnly: true,
|
|
include: [resolve(__dirname, 'src/locales/**')]
|
|
}),
|
|
createSvgIconsPlugin({
|
|
iconDirs: [pathResolve('src/assets/svgs')],
|
|
symbolId: 'icon-[dir]-[name]'
|
|
}),
|
|
// viteCompression({
|
|
// verbose: true, // 是否在控制台输出压缩结果
|
|
// disable: false, // 是否禁用
|
|
// threshold: 10240, // 体积大于 threshold 才会被压缩,单位 b
|
|
// algorithm: 'gzip', // 压缩算法,可选 [ 'gzip' , 'brotliCompress' ,'deflate' , 'deflateRaw']
|
|
// ext: '.gz', // 生成的压缩包后缀
|
|
// deleteOriginFile: false //压缩后是否删除源文件
|
|
// }),
|
|
ViteEjsPlugin(),
|
|
topLevelAwait({
|
|
// https://juejin.cn/post/7152191742513512485
|
|
// The export name of top-level await promise for each chunk module
|
|
promiseExportName: '__tla',
|
|
// The function to generate import names of top-level await promise in each chunk module
|
|
promiseImportName: (i) => `__tla_${i}`
|
|
}),
|
|
// visualizer({
|
|
// gzipSize: false,
|
|
// brotliSize: false,
|
|
// emitFile: false,
|
|
// filename: 'test.html', //分析图生成的文件名
|
|
// open: true
|
|
// })
|
|
]
|
|
}
|
|
|