vite.config.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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('lodash-es')) return 'vendor-lodash'
  37. if (id.includes('echarts')) return 'vendor-echarts'
  38. return 'vendor'
  39. }
  40. },
  41. },
  42. },
  43. },
  44. }
  45. })