vite.config.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { fileURLToPath, URL } from 'node:url'
  2. import { defineConfig, loadEnv, UserConfig } from 'vite'
  3. import vue from '@vitejs/plugin-vue'
  4. // https://vite.dev/config/
  5. export default defineConfig(({ mode }): UserConfig => {
  6. const root = process.cwd()
  7. const env = loadEnv(mode, root)
  8. // const isProduction = mode === 'production'
  9. return {
  10. base: '/h5/',
  11. plugins: [vue()].filter(Boolean),
  12. resolve: {
  13. alias: {
  14. '@': fileURLToPath(new URL('./src', import.meta.url)),
  15. },
  16. },
  17. server: {
  18. open: false,
  19. proxy: {
  20. '/api': {
  21. target: env.VITE_APP_URL,
  22. changeOrigin: true,
  23. rewrite: (path) => path.replace(/^\/api/, ''),
  24. },
  25. },
  26. },
  27. build: {
  28. rollupOptions: {
  29. output: {
  30. entryFileNames: `assets/[name].[hash].js`,
  31. chunkFileNames: `assets/[name].[hash].js`,
  32. assetFileNames: `assets/[name].[hash].[ext]`,
  33. // 使用 Vite 原生 manualChunks 替代 chunk-split 插件
  34. manualChunks(id: string) {
  35. if (id.includes('node_modules')) {
  36. if (id.includes('@vant/area-data')) return 'area-data'
  37. if (id.includes('lodash-es')) return 'vendor-lodash'
  38. if (id.includes('echarts')) return 'vendor-echarts'
  39. return 'vendor'
  40. }
  41. },
  42. },
  43. },
  44. },
  45. }
  46. })