/* * @Author: Haijun Zhang * @Date: 2022-11-10 10:46:38 * @LastEditTime: 2022-11-10 12:10:52 * @LastEditors: Haijun Zhang * @Description: * @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' import { ElementPlusResolver } from 'unplugin-vue-components/resolvers' 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({ prefix: 'Icon' }) ], eslintrc: { // 已存在文件设置默认 false,需要更新时再打开,防止每次更新都重新生成 enabled: false, // 生成文件地址和名称 filepath: './.eslintrc-auto-import.json', globalsPropValue: true }, dts: path.resolve(pathSrc, 'auto-imports.d.ts') }), 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({ prefix: 'icon' // enabledCollections: ['ep'], }) ], dts: path.resolve(pathSrc, 'components.d.ts') }), Icons({ autoInstall: true }), createStyleImportPlugin({ libs: [ // { libraryName: 'element-plus', esModule: true, resolveStyle: name => { const component = name.replace('el-', '') return `element-plus/theme-chalk/src/${component}.scss` } } ] }), Unocss(), eslintPlugin({ include: ['src/**/*.ts', 'src/**/*.vue', 'src/**/*.js'] }) ]