vite.config.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 pkg from './package.json'
  9. export default defineConfig({
  10. plugins: [
  11. process.env.NODE_ENV === 'development' && vueDevTools(),
  12. vue(),
  13. AutoImport({
  14. imports: ['vue', 'vue-router', 'pinia'],
  15. resolvers: [ElementPlusResolver()],
  16. dts: 'src/auto-imports.d.ts',
  17. eslintrc: {
  18. enabled: true,
  19. filepath: './.eslintrc-auto-import.json',
  20. globalsPropValue: true
  21. }
  22. }),
  23. Components({
  24. resolvers: [ElementPlusResolver()],
  25. dts: 'src/components.d.ts'
  26. })
  27. ],
  28. define: {
  29. __APP_VERSION__: JSON.stringify(pkg.version)
  30. },
  31. resolve: {
  32. alias: {
  33. '@': resolve(__dirname, 'src')
  34. }
  35. },
  36. server: {
  37. host: '0.0.0.0',
  38. port: 3000,
  39. open: true,
  40. proxy: {
  41. // 后端 API
  42. '/api': {
  43. target: 'https://tg-live-game.pwtk.cc',
  44. changeOrigin: true,
  45. secure: false // 禁用 SSL 证书验证(开发环境)
  46. }
  47. }
  48. },
  49. css: {
  50. preprocessorOptions: {
  51. scss: {
  52. additionalData: `@use "@/assets/styles/variables.scss" as *;`,
  53. silenceDeprecations: ['legacy-js-api']
  54. }
  55. }
  56. },
  57. build: {
  58. chunkSizeWarningLimit: 1500,
  59. rollupOptions: {
  60. output: {
  61. manualChunks(id) {
  62. if (id.includes('node_modules')) {
  63. // Vue 核心和 Element Plus 放在一起,避免循环依赖
  64. if (
  65. id.includes('vue') ||
  66. id.includes('@vue') ||
  67. id.includes('element-plus') ||
  68. id.includes('@element-plus') ||
  69. id.includes('pinia') ||
  70. id.includes('vue-router')
  71. ) {
  72. return 'vendor'
  73. }
  74. }
  75. }
  76. }
  77. }
  78. }
  79. })