vite.config.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import { defineConfig } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import vueDevTools from 'vite-plugin-vue-devtools'
  4. import { resolve } from 'path'
  5. import AutoImport from 'unplugin-auto-import/vite'
  6. import Components from 'unplugin-vue-components/vite'
  7. import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
  8. import Icons from 'unplugin-icons/vite'
  9. import IconsResolver from 'unplugin-icons/resolver'
  10. import pkg from './package.json'
  11. export default defineConfig({
  12. plugins: [
  13. process.env.NODE_ENV === 'development' && vueDevTools(),
  14. vue(),
  15. AutoImport({
  16. imports: [
  17. 'vue',
  18. 'vue-router',
  19. 'pinia',
  20. {
  21. '@iconify/vue': ['Icon']
  22. }
  23. ],
  24. resolvers: [
  25. ElementPlusResolver(),
  26. IconsResolver({
  27. prefix: 'Icon'
  28. })
  29. ],
  30. dts: 'src/auto-imports.d.ts',
  31. eslintrc: {
  32. enabled: true,
  33. filepath: './.eslintrc-auto-import.json',
  34. globalsPropValue: true
  35. }
  36. }),
  37. Components({
  38. resolvers: [
  39. ElementPlusResolver(),
  40. IconsResolver({
  41. enabledCollections: ['ep', 'mdi', 'ri']
  42. })
  43. ],
  44. dts: 'src/components.d.ts'
  45. }),
  46. Icons({
  47. autoInstall: false
  48. })
  49. ],
  50. define: {
  51. __APP_VERSION__: JSON.stringify(pkg.version)
  52. },
  53. resolve: {
  54. alias: {
  55. '@': resolve(__dirname, 'src')
  56. }
  57. },
  58. server: {
  59. host: '0.0.0.0',
  60. port: 3000,
  61. open: true,
  62. proxy: {
  63. // 后端 API
  64. '/api': {
  65. target: 'https://tg-live-game.pwtk.cc',
  66. changeOrigin: true,
  67. secure: false // 禁用 SSL 证书验证(开发环境)
  68. },
  69. // PTZ 摄像头控制
  70. '/camera/control': {
  71. target: 'http://localhost:3002',
  72. changeOrigin: true,
  73. rewrite: (path) => path.replace(/^\/camera\/control/, '')
  74. }
  75. }
  76. },
  77. css: {
  78. preprocessorOptions: {
  79. scss: {
  80. additionalData: `@use "@/assets/styles/variables.scss" as *;`,
  81. silenceDeprecations: ['legacy-js-api']
  82. }
  83. }
  84. },
  85. build: {
  86. emptyOutDir: true, // 确保每次构建前清空 dist 目录
  87. chunkSizeWarningLimit: 1500,
  88. rollupOptions: {
  89. output: {
  90. manualChunks(id) {
  91. if (id.includes('node_modules')) {
  92. // Vue 核心、Element Plus、vue-i18n 放在一起,避免循环依赖和模块初始化顺序问题
  93. if (
  94. id.includes('vue') ||
  95. id.includes('@vue') ||
  96. id.includes('element-plus') ||
  97. id.includes('@element-plus') ||
  98. id.includes('pinia') ||
  99. id.includes('vue-router') ||
  100. id.includes('vue-i18n')
  101. ) {
  102. return 'vendor'
  103. }
  104. }
  105. }
  106. }
  107. }
  108. }
  109. })