import { vitePlugin as remix } from "@remix-run/dev"; import { defineConfig } from "vite"; import tsconfigPaths from "vite-tsconfig-paths"; declare module "@remix-run/node" { interface Future { v3_singleFetch: true; } } export default defineConfig({ plugins: [ remix({ future: { v3_fetcherPersist: true, v3_relativeSplatPath: true, v3_throwAbortReason: true, v3_singleFetch: true, v3_lazyRouteDiscovery: true, }, }), tsconfigPaths(), ], define: { // 在构建时为客户端代码提供环境变量 // NODE_ENV: 当前运行环境,影响API配置选择 // - development: 开发环境,使用本地API服务器 // - testing: 测试环境,使用测试API服务器 // - production: 生产环境,使用生产API服务器 "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV || "development"), // 注意:移除端口相关的硬编码,改为运行时动态获取 // PORT和API_PORT_CONFIG将在运行时通过环境变量或启动参数获取 // CLIENT_ID: 客户端标识,用于区分不同地区的客户端(可选) // - main: 主服务 // - chaozhou: 潮州客户端 // - jieyang: 揭阳客户端 // - yunfu: 云浮客户端 // - meizhou: 梅州客户端 // - province: 省局客户端 "process.env.CLIENT_ID": JSON.stringify(process.env.CLIENT_ID || "main"), // NEXT_PUBLIC_前缀的环境变量,确保客户端能获取到 "process.env.NEXT_PUBLIC_NODE_ENV": JSON.stringify(process.env.NEXT_PUBLIC_NODE_ENV || process.env.NODE_ENV || "development"), "process.env.NEXT_PUBLIC_CLIENT_ID": JSON.stringify(process.env.NEXT_PUBLIC_CLIENT_ID || process.env.CLIENT_ID || "main"), // 注意:移除了 NEXT_PUBLIC_API_BASE_URL 和 NEXT_PUBLIC_API_ENV // 这些变量会覆盖多客户端配置逻辑,导致配置冲突 // 如需特殊配置,请直接修改 api-config.ts 中的配置 }, server: { host: '0.0.0.0', // port: 5173, port: Number(process.env.PORT) || 51709, open: true, // open: false, allowedHosts: ['nas.7bm.co', 'localhost', '127.0.0.1'], // 允许的主机名列表1 cors: true, // HMR配置 hmr: { // 控制HMR更新时行为 overlay: false, }, }, // 优化依赖预构建配置 optimizeDeps: { // 防止依赖预构建时触发页面刷新导致路由中断 force: false, // 预构建这些依赖,避免首次加载时出现重新构建 include: ['react-pdf', 'pdfjs-dist', 'dayjs', '@remix-run/node', 'react-dom', 'axios', 'dayjs/plugin/utc', '@remix-run/react', 'react-router-dom', 'jszip', 'ahooks', 'antd', 'immer', '@ant-design/icons', 'react-markdown', 'remark-math', 'remark-breaks', 'rehype-katex', 'remark-gfm'], }, });