vite.config.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { defineConfig } from "vite";
  2. import uni from "@dcloudio/vite-plugin-uni";
  3. // https://vitejs.dev/config/
  4. export default defineConfig({
  5. plugins: [uni()],
  6. build: {
  7. rollupOptions: {
  8. output: {
  9. // 把跨页面共享的核心模块(导航 store / 全局组件)固定到一个共享 chunk。
  10. // 原因:不同 Node 环境下 rollup 的自动 chunk 拆分结果不稳定,曾出现
  11. // navigation store / CustomTabBar 被内联进单个页面 chunk,导致其它
  12. // 页面(如首页)拿不到底部 tab 栏、用户中心菜单为空。
  13. // 固定成命名 chunk 后,所有引用它的页面 chunk 都会显式 import 它,保证
  14. // 全局单例与组件在任何构建环境下都可用。
  15. manualChunks(id) {
  16. if (id.includes('/src/store/navigation') || id.includes('\\src\\store\\navigation')) {
  17. return 'app-core';
  18. }
  19. if (id.includes('/src/components/CustomTabBar') || id.includes('\\src\\components\\CustomTabBar')) {
  20. return 'app-core';
  21. }
  22. return undefined;
  23. },
  24. },
  25. },
  26. },
  27. server: {
  28. host: '0.0.0.0',
  29. port: 5173,
  30. proxy: {
  31. '/api': {
  32. target: 'http://localhost:3000',
  33. changeOrigin: true,
  34. },
  35. '/uploads': {
  36. target: 'http://localhost:3000',
  37. changeOrigin: true,
  38. },
  39. '/videos': {
  40. target: 'http://localhost:3000',
  41. changeOrigin: true,
  42. },
  43. '/cache': {
  44. target: 'http://localhost:3000',
  45. changeOrigin: true,
  46. },
  47. },
  48. },
  49. });