refactor ts
This commit is contained in:
24
Vite/plugins/auto-import.ts
Normal file
24
Vite/plugins/auto-import.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import AutoImport from 'unplugin-auto-import/vite';
|
||||
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
|
||||
import IconsResolver from 'unplugin-icons/resolver';
|
||||
|
||||
export default (path: any) => {
|
||||
return AutoImport({
|
||||
// 自动导入 Vue 相关函数
|
||||
imports: ['vue', 'vue-router', '@vueuse/core', 'pinia'],
|
||||
eslintrc: {
|
||||
enabled: false,
|
||||
filepath: './.eslintrc-auto-import.json',
|
||||
globalsPropValue: true
|
||||
},
|
||||
resolvers: [
|
||||
// 自动导入 Element Plus 相关函数ElMessage, ElMessageBox... (带样式)
|
||||
ElementPlusResolver(),
|
||||
IconsResolver({
|
||||
prefix: 'Icon'
|
||||
})
|
||||
],
|
||||
vueTemplate: true, // 是否在 vue 模板中自动导入
|
||||
dts: path.resolve(path.resolve(__dirname, '../../src'), 'types', 'auto-imports.d.ts')
|
||||
});
|
||||
};
|
17
Vite/plugins/components.ts
Normal file
17
Vite/plugins/components.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import Components from 'unplugin-vue-components/vite';
|
||||
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
|
||||
import IconsResolver from 'unplugin-icons/resolver';
|
||||
|
||||
export default (path: any) => {
|
||||
return Components({
|
||||
resolvers: [
|
||||
// 自动导入 Element Plus 组件
|
||||
ElementPlusResolver(),
|
||||
// 自动注册图标组件
|
||||
IconsResolver({
|
||||
enabledCollections: ['ep']
|
||||
})
|
||||
],
|
||||
dts: path.resolve(path.resolve(__dirname, '../../src'), 'types', 'components.d.ts')
|
||||
});
|
||||
};
|
8
Vite/plugins/icons.ts
Normal file
8
Vite/plugins/icons.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import Icons from 'unplugin-icons/vite';
|
||||
|
||||
export default () => {
|
||||
return Icons({
|
||||
// 自动安装图标库
|
||||
autoInstall: true
|
||||
});
|
||||
};
|
18
Vite/plugins/index.ts
Normal file
18
Vite/plugins/index.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import vue from '@vitejs/plugin-vue';
|
||||
import createUnoCss from './unocss';
|
||||
import createAutoImport from './auto-import';
|
||||
import createComponents from './components';
|
||||
import createIcons from './icons';
|
||||
import createSvgIconsPlugin from './svg-icon';
|
||||
import path from 'path';
|
||||
|
||||
export default (viteEnv, isBuild = false): [] => {
|
||||
const vitePlusgins: any = [];
|
||||
vitePlusgins.push(vue());
|
||||
vitePlusgins.push(createUnoCss());
|
||||
vitePlusgins.push(createAutoImport(path));
|
||||
vitePlusgins.push(createComponents(path));
|
||||
vitePlusgins.push(createIcons());
|
||||
vitePlusgins.push(createSvgIconsPlugin(path));
|
||||
return vitePlusgins;
|
||||
};
|
9
Vite/plugins/svg-icon.ts
Normal file
9
Vite/plugins/svg-icon.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
|
||||
export default (path: any) => {
|
||||
return createSvgIconsPlugin({
|
||||
// 指定需要缓存的图标文件夹
|
||||
iconDirs: [path.resolve(path.resolve(__dirname, '../../src'), 'assets/icons/svg')],
|
||||
// 指定symbolId格式
|
||||
symbolId: 'icon-[dir]-[name]'
|
||||
});
|
||||
};
|
13
Vite/plugins/unocss.ts
Normal file
13
Vite/plugins/unocss.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import UnoCss from 'unocss/vite';
|
||||
import { presetUno, presetAttributify, presetIcons } from 'unocss';
|
||||
|
||||
export default () => {
|
||||
return UnoCss({
|
||||
presets: [presetUno(), presetAttributify(), presetIcons()],
|
||||
// rules: [['search', {}]],
|
||||
shortcuts: {
|
||||
'panel-title':
|
||||
'pb-[5px] font-sans leading-[1.1] font-medium text-base text-[#6379bb] border-b border-b-solid border-[var(--el-border-color-light)] mb-5 mt-0'
|
||||
}
|
||||
});
|
||||
};
|
Reference in New Issue
Block a user