vite.config.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { fileURLToPath, URL } from 'node:url'
  2. import path from 'path'
  3. import { defineConfig, loadEnv, splitVendorChunkPlugin } 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. console.log(mode)
  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. splitVendorChunkPlugin(),
  40. mode === 'production' && env.VITE_SENTRY_DSN
  41. ? sentryVitePlugin({
  42. org: env.VITE_SENTRY_ORG,
  43. project: env.VITE_SENTRY_PROJECT,
  44. authToken: env.VITE_SENTRY_AUTH_TOKEN,
  45. release: {
  46. name: env.VITE_SENTRY_RELEASE
  47. },
  48. sourcemaps: {
  49. assets: ['./dist/assets'],
  50. ignore: ['node_modules']
  51. }
  52. })
  53. : null
  54. ],
  55. resolve: {
  56. alias: {
  57. '@': fileURLToPath(new URL('./src', import.meta.url))
  58. }
  59. },
  60. server: {
  61. proxy: {
  62. [env.VITE_BASE_API]: {
  63. target: env.VITE_BASE_PATH,
  64. changeOrigin: true
  65. }
  66. },
  67. hmr: {
  68. overlay: false
  69. }
  70. },
  71. build: {
  72. sourcemap: !!env.VITE_SENTRY_DSN
  73. }
  74. }
  75. })