2023-02-10 16:44:00 +00:00
|
|
|
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 { ViteEjsPlugin } from 'vite-plugin-ejs'
|
2023-03-30 08:04:46 +00:00
|
|
|
// @ts-ignore
|
2023-02-10 16:44:00 +00:00
|
|
|
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'
|
2023-04-04 14:08:17 +00:00
|
|
|
import topLevelAwait from 'vite-plugin-top-level-await'
|
2023-02-10 16:44:00 +00:00
|
|
|
import VueI18nPlugin from '@intlify/unplugin-vue-i18n/vite'
|
|
|
|
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
|
2023-07-29 06:40:55 +00:00
|
|
|
import UnoCSS from 'unocss/vite'
|
2023-03-07 11:21:39 +00:00
|
|
|
|
2023-03-23 01:42:01 +00:00
|
|
|
export function createVitePlugins() {
|
2023-02-10 16:44:00 +00:00
|
|
|
const root = process.cwd()
|
2023-04-14 14:40:05 +00:00
|
|
|
|
2023-02-10 16:44:00 +00:00
|
|
|
// 路径查找
|
|
|
|
function pathResolve(dir: string) {
|
|
|
|
return resolve(root, '.', dir)
|
|
|
|
}
|
2023-04-14 14:40:05 +00:00
|
|
|
|
2023-02-10 16:44:00 +00:00
|
|
|
return [
|
|
|
|
Vue(),
|
|
|
|
VueJsx(),
|
2023-07-29 06:40:55 +00:00
|
|
|
UnoCSS(),
|
2023-02-10 16:44:00 +00:00
|
|
|
progress(),
|
|
|
|
PurgeIcons(),
|
2023-03-07 02:05:45 +00:00
|
|
|
ElementPlus({}),
|
2023-02-10 16:44:00 +00:00
|
|
|
AutoImport({
|
|
|
|
include: [
|
|
|
|
/\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
|
|
|
|
/\.vue$/,
|
|
|
|
/\.vue\?vue/, // .vue
|
|
|
|
/\.md$/ // .md
|
|
|
|
],
|
|
|
|
imports: [
|
|
|
|
'vue',
|
|
|
|
'vue-router',
|
2023-03-17 14:58:49 +00:00
|
|
|
// 可额外添加需要 autoImport 的组件
|
2023-02-10 16:44:00 +00:00
|
|
|
{
|
|
|
|
'@/hooks/web/useI18n': ['useI18n'],
|
|
|
|
'@/hooks/web/useMessage': ['useMessage'],
|
2023-03-17 14:58:49 +00:00
|
|
|
'@/hooks/web/useTable': ['useTable'],
|
|
|
|
'@/hooks/web/useCrudSchemas': ['useCrudSchemas'],
|
2023-02-10 16:44:00 +00:00
|
|
|
'@/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()],
|
2023-11-09 07:48:20 +00:00
|
|
|
globs: ["src/components/**/**.{vue, md}", '!src/components/DiyEditor/components/mobile/**']
|
2023-02-10 16:44:00 +00:00
|
|
|
}),
|
|
|
|
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]',
|
|
|
|
svgoOptions: true
|
|
|
|
}),
|
|
|
|
viteCompression({
|
|
|
|
verbose: true, // 是否在控制台输出压缩结果
|
|
|
|
disable: false, // 是否禁用
|
|
|
|
threshold: 10240, // 体积大于 threshold 才会被压缩,单位 b
|
|
|
|
algorithm: 'gzip', // 压缩算法,可选 [ 'gzip' , 'brotliCompress' ,'deflate' , 'deflateRaw']
|
|
|
|
ext: '.gz', // 生成的压缩包后缀
|
|
|
|
deleteOriginFile: false //压缩后是否删除源文件
|
|
|
|
}),
|
2023-04-04 14:08:17 +00:00
|
|
|
ViteEjsPlugin(),
|
2023-04-10 08:55:02 +00:00
|
|
|
topLevelAwait({
|
|
|
|
// https://juejin.cn/post/7152191742513512485
|
2023-04-04 14:08:17 +00:00
|
|
|
// 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}`
|
|
|
|
})
|
2023-02-10 16:44:00 +00:00
|
|
|
]
|
|
|
|
}
|