vite.config.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import { fileURLToPath, URL } from 'node:url'
  2. import path from 'path'
  3. import { defineConfig, loadEnv } from 'vite'
  4. import vue from '@vitejs/plugin-vue'
  5. import vueJsx from '@vitejs/plugin-vue-jsx'
  6. import Icons from 'unplugin-icons/vite'
  7. import IconsResolver from 'unplugin-icons/resolver'
  8. import AutoImport from 'unplugin-auto-import/vite'
  9. import Components from 'unplugin-vue-components/vite'
  10. import DefineOptions from 'unplugin-vue-define-options/vite'
  11. import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
  12. import { createStyleImportPlugin, VxeTableResolve } from 'vite-plugin-style-import'
  13. import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
  14. import Unocss from 'unocss/vite'
  15. export default defineConfig(({ mode }) => {
  16. const env = loadEnv(mode, process.cwd(), '')
  17. return {
  18. plugins: [
  19. vue(),
  20. vueJsx(),
  21. Unocss(),
  22. DefineOptions(),
  23. AutoImport({
  24. resolvers: [
  25. ElementPlusResolver(),
  26. // 自动导入图标组件
  27. IconsResolver({
  28. prefix: 'Icon'
  29. })
  30. ],
  31. imports: ['vue', 'vue-router', 'pinia', '@vueuse/core'],
  32. dts: 'src/auto-import.d.ts'
  33. }),
  34. Components({
  35. resolvers: [
  36. ElementPlusResolver(),
  37. // 自动注册图标组件
  38. IconsResolver({
  39. enabledCollections: ['ep']
  40. })
  41. ],
  42. dirs: ['src/components'],
  43. extensions: ['vue'],
  44. dts: 'src/components.d.ts'
  45. }),
  46. Icons({
  47. autoInstall: true
  48. }),
  49. createSvgIconsPlugin({
  50. iconDirs: [path.resolve(process.cwd(), 'src/assets/svg')],
  51. symbolId: 'icon-[dir]-[name]'
  52. }),
  53. createStyleImportPlugin({
  54. resolves: [VxeTableResolve()]
  55. })
  56. ],
  57. resolve: {
  58. alias: {
  59. '@': fileURLToPath(new URL('./src', import.meta.url))
  60. }
  61. },
  62. server: {
  63. proxy: {
  64. [env.VITE_BASE_API]: {
  65. target: env.VITE_BASE_PATH,
  66. changeOrigin: true
  67. }
  68. },
  69. hmr: {
  70. overlay: false
  71. }
  72. },
  73. build: {
  74. sourcemap: !!env.VITE_SENTRY_DSN,
  75. rollupOptions: {
  76. output: {
  77. manualChunks: (id: string) => {
  78. if (id.includes('node_modules')) {
  79. return 'vender'
  80. }
  81. }
  82. }
  83. }
  84. }
  85. }
  86. })