vite.config.ts 2.3 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. 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. 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. ],
  54. resolve: {
  55. alias: {
  56. '@': fileURLToPath(new URL('./src', import.meta.url))
  57. }
  58. },
  59. server: {
  60. proxy: {
  61. [env.VITE_BASE_API]: {
  62. target: env.VITE_BASE_PATH,
  63. changeOrigin: true
  64. }
  65. },
  66. hmr: {
  67. overlay: false
  68. }
  69. },
  70. build: {
  71. sourcemap: !!env.VITE_SENTRY_DSN,
  72. rollupOptions: {
  73. output: {
  74. manualChunks: (id) => {
  75. if (id.includes('node_modules')) {
  76. return 'vender'
  77. }
  78. }
  79. }
  80. }
  81. }
  82. }
  83. })