vite.config.ts 2.2 KB

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