// Umi 3 基础配置(中文注释) // 目标: // - 显式启用 routes.ts(保持与原项目路径兼容,支持 *.html 路径) // - 使用 browser history,开发调试直达路径不 404;产物 publicPath 保持相对路径便于静态托管 // - 开发环境走 proxy 转发后端,避免跨域 import routes from './routes'; import proxy from './proxy'; const { REACT_APP_ENV } = process.env as any; const isDev = process.env.NODE_ENV === 'development'; // 构建期注入 API 前缀(生产包/测试包/预发包),开发环境走代理不加前缀 const API_PREFIX = isDev ? '' : (process.env.API_PREFIX || ''); const APP_BASE = isDev ? '/' : (process.env.APP_BASE || '/'); export default { hash: true, // 资源路径:开发用根路径,生产为相对路径 publicPath: isDev ? '/' : (APP_BASE.endsWith('/') ? APP_BASE : APP_BASE + '/'), antd: {}, // 页面 meta 标签 metas: [ { charset: 'utf-8' }, { name: 'viewport', content: 'width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' }, ], // 主题(现代风格 + 红绿配主色) theme: { 'primary-color': '#ff4d4f', 'border-radius-base': '8px', 'box-shadow-base': '0 8px 32px rgba(0, 0, 0, 0.1)', 'animation-duration-slow': '0.4s', 'animation-duration-base': '0.3s', 'animation-duration-fast': '0.2s', }, // 关闭 i18n,多语言后续按需启用 locale: { antd: false, default: 'zh-CN', baseNavigator: true }, // 使用按需编译的动态导入,提升首屏 dynamicImport: { loading: '@/components/PageLoading' }, // 路由采用显式配置 routes, // 历史模式 history: { type: 'browser' }, base: APP_BASE, // Dev 代理 proxy: (proxy as any)[REACT_APP_ENV || 'dev'], // 向业务代码注入构建期常量 define: { 'process.env.API_PREFIX': API_PREFIX, 'process.env.APP_BASE': APP_BASE, }, // 构建优化 nodeModulesTransform: { type: 'none' }, mfsu: false, fastRefresh: {}, // Cesium 静态资源配置 chainWebpack: (config: any) => { // 配置 Cesium 资源路径 config.plugin('define').tap((definitions: any) => { Object.assign(definitions[0], { 'process.env.CESIUM_BASE_URL': JSON.stringify(isDev ? '/' : (APP_BASE.endsWith('/') ? APP_BASE : APP_BASE + '/')), }); return definitions; }); return config; }, } as any;