vite.plugin.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { resolve } from 'path'
  2. import Vue from '@vitejs/plugin-vue'
  3. // @ts-ignore
  4. import AutoImport from 'unplugin-auto-import/vite'
  5. export function createVitePlugins() {
  6. const root = process.cwd()
  7. // 路径查找
  8. function pathResolve(dir: string) {
  9. return resolve(root, '.', dir)
  10. }
  11. return [
  12. Vue(),
  13. AutoImport({
  14. include: [
  15. /\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
  16. /\.vue$/,
  17. /\.vue\?vue/, // .vue
  18. /\.md$/ // .md
  19. ],
  20. imports: [
  21. 'vue',
  22. 'vue-router',
  23. // 可额外添加需要 autoImport 的组件
  24. {
  25. '@/hooks/web/useI18n': ['useI18n'],
  26. '@/hooks/web/useMessage': ['useMessage'],
  27. '@/hooks/web/useTable': ['useTable'],
  28. '@/hooks/web/useCrudSchemas': ['useCrudSchemas'],
  29. '@/utils/formRules': ['required'],
  30. '@/utils/dict': ['DICT_TYPE']
  31. }
  32. ],
  33. dts: 'src/types/auto-imports.d.ts',
  34. eslintrc: {
  35. enabled: false, // Default `false`
  36. filepath: './.eslintrc-auto-import.json', // Default `./.eslintrc-auto-import.json`
  37. globalsPropValue: true // Default `true`, (true | false | 'readonly' | 'readable' | 'writable' | 'writeable')
  38. }
  39. }),
  40. ]
  41. }