import { defineConfig } from "vite"; import uni from "@dcloudio/vite-plugin-uni"; // https://vitejs.dev/config/ export default defineConfig({ plugins: [uni()], build: { rollupOptions: { output: { // 把跨页面共享的核心模块(导航 store / 全局组件)固定到一个共享 chunk。 // 原因:不同 Node 环境下 rollup 的自动 chunk 拆分结果不稳定,曾出现 // navigation store / CustomTabBar 被内联进单个页面 chunk,导致其它 // 页面(如首页)拿不到底部 tab 栏、用户中心菜单为空。 // 固定成命名 chunk 后,所有引用它的页面 chunk 都会显式 import 它,保证 // 全局单例与组件在任何构建环境下都可用。 manualChunks(id) { if (id.includes('/src/store/navigation') || id.includes('\\src\\store\\navigation')) { return 'app-core'; } if (id.includes('/src/components/CustomTabBar') || id.includes('\\src\\components\\CustomTabBar')) { return 'app-core'; } return undefined; }, }, }, }, server: { host: '0.0.0.0', port: 5173, proxy: { '/api': { target: 'http://localhost:3000', changeOrigin: true, }, '/uploads': { target: 'http://localhost:3000', changeOrigin: true, }, '/videos': { target: 'http://localhost:3000', changeOrigin: true, }, '/cache': { target: 'http://localhost:3000', changeOrigin: true, }, }, }, });