main-web/build/plugin.ts

84 lines
2.3 KiB
TypeScript
Raw Permalink Normal View History

2024-08-20 12:11:33 +00:00
/*
* @Author: Haijun Zhang
* @Date: 2022-11-10 10:46:38
* @LastEditTime: 2022-11-10 12:10:52
* @LastEditors: Haijun Zhang
2024-08-21 01:17:14 +00:00
* @Description:
2024-08-20 12:11:33 +00:00
* @FilePath: \main-web-qiankun\build\plugin.ts
*/
import vue from '@vitejs/plugin-vue'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import Components from 'unplugin-vue-components/vite'
2024-08-26 06:30:29 +00:00
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
2024-08-20 12:11:33 +00:00
import Icons from 'unplugin-icons/vite'
import IconsResolver from 'unplugin-icons/resolver'
import AutoImport from 'unplugin-auto-import/vite'
import { createStyleImportPlugin } from 'vite-plugin-style-import'
import path from 'path'
import Unocss from 'unocss/vite'
import eslintPlugin from 'vite-plugin-eslint'
const pathSrc = path.resolve(__dirname, '../src')
export default [
vue(),
AutoImport({
// 自动导入 Vue 相关函数ref, reactive, toRef 等
imports: ['vue'],
// 自动导入 Element Plus 相关函数ElMessage, ElMessageBox...
resolvers: [
ElementPlusResolver(),
// 自动导入图标组件
IconsResolver({
2024-08-21 01:17:14 +00:00
prefix: 'Icon'
2024-08-20 12:11:33 +00:00
})
],
eslintrc: {
// 已存在文件设置默认 false需要更新时再打开防止每次更新都重新生成
enabled: false,
// 生成文件地址和名称
filepath: './.eslintrc-auto-import.json',
2024-08-21 01:17:14 +00:00
globalsPropValue: true
2024-08-20 12:11:33 +00:00
},
2024-08-21 01:17:14 +00:00
dts: path.resolve(pathSrc, 'auto-imports.d.ts')
2024-08-20 12:11:33 +00:00
}),
createSvgIconsPlugin({
// Specify the icon folder to be cached
iconDirs: [path.resolve(process.cwd(), './src/icons/svg')],
// Specify symbolId format
symbolId: 'icon-[dir]-[name]'
}),
Components({
resolvers: [
ElementPlusResolver({
importStyle: 'sass'
}),
// 自动注册图标组件
IconsResolver({
2024-08-21 01:17:14 +00:00
prefix: 'icon'
2024-08-20 12:11:33 +00:00
// enabledCollections: ['ep'],
})
],
2024-08-21 01:17:14 +00:00
dts: path.resolve(pathSrc, 'components.d.ts')
2024-08-20 12:11:33 +00:00
}),
Icons({
2024-08-21 01:17:14 +00:00
autoInstall: true
2024-08-20 12:11:33 +00:00
}),
createStyleImportPlugin({
libs: [
2024-08-21 01:17:14 +00:00
//
2024-08-20 12:11:33 +00:00
{
libraryName: 'element-plus',
esModule: true,
2024-08-21 01:17:14 +00:00
resolveStyle: name => {
const component = name.replace('el-', '')
2024-08-20 12:11:33 +00:00
return `element-plus/theme-chalk/src/${component}.scss`
}
}
]
}),
Unocss(),
eslintPlugin({
2024-08-21 01:17:14 +00:00
include: ['src/**/*.ts', 'src/**/*.vue', 'src/**/*.js']
2024-08-20 12:11:33 +00:00
})
2024-08-21 01:17:14 +00:00
]