vite.config.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 AutoImport from 'unplugin-auto-import/vite'
  7. import Components from 'unplugin-vue-components/vite'
  8. import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
  9. import { createStyleImportPlugin, VxeTableResolve } from 'vite-plugin-style-import'
  10. import Unocss from 'unocss/vite'
  11. import VueDevTools from 'vite-plugin-vue-devtools'
  12. import { sentryVitePlugin } from '@sentry/vite-plugin'
  13. import { lazyImport, VxeResolver } from 'vite-plugin-lazy-import'
  14. export default defineConfig(({ mode }) => {
  15. const env = loadEnv(mode, process.cwd(), '')
  16. return {
  17. base: '/',
  18. plugins: [
  19. vue(),
  20. vueJsx(),
  21. Unocss(),
  22. VueDevTools(),
  23. AutoImport({
  24. imports: ['vue', 'vue-router', 'pinia', '@vueuse/core'],
  25. dts: 'src/auto-import.d.ts'
  26. }),
  27. Components({
  28. dirs: ['src/components'],
  29. extensions: ['vue'],
  30. dts: 'src/components.d.ts'
  31. }),
  32. createSvgIconsPlugin({
  33. iconDirs: [path.resolve(process.cwd(), 'src/assets/svg')],
  34. symbolId: 'icon-[dir]-[name]'
  35. }),
  36. createStyleImportPlugin({
  37. resolves: [VxeTableResolve()]
  38. }),
  39. mode === 'production' && env.VITE_SENTRY_DSN
  40. ? sentryVitePlugin({
  41. org: env.VITE_SENTRY_ORG,
  42. project: env.VITE_SENTRY_PROJECT,
  43. authToken: env.VITE_SENTRY_AUTH_TOKEN,
  44. release: {
  45. name: env.VITE_SENTRY_RELEASE
  46. },
  47. sourcemaps: {
  48. assets: ['./dist/assets'],
  49. ignore: ['node_modules']
  50. }
  51. })
  52. : null,
  53. lazyImport({
  54. resolvers: [
  55. VxeResolver({
  56. libraryName: 'vxe-table'
  57. }),
  58. VxeResolver({
  59. libraryName: 'vxe-pc-ui'
  60. })
  61. ]
  62. })
  63. ],
  64. resolve: {
  65. alias: {
  66. '@': fileURLToPath(new URL('./src', import.meta.url))
  67. }
  68. },
  69. server: {
  70. proxy: {
  71. [env.VITE_BASE_API]: {
  72. target: env.VITE_BASE_PATH,
  73. changeOrigin: true
  74. }
  75. },
  76. hmr: {
  77. overlay: false
  78. }
  79. },
  80. build: {
  81. sourcemap: !!env.VITE_SENTRY_DSN,
  82. rollupOptions: {
  83. output: {
  84. manualChunks: id => {
  85. if (id.includes('node_modules')) {
  86. return 'vender'
  87. }
  88. }
  89. }
  90. }
  91. }
  92. }
  93. })