vite.config.ts 1.8 KB

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