config.ts 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. // https://umijs.org/config/
  2. import { defineConfig } from '@umijs/max';
  3. import { join } from 'path';
  4. import defaultSettings from './defaultSettings';
  5. import proxy from './proxy';
  6. import routes from './routes';
  7. const { REACT_APP_ENV = 'dev' } = process.env;
  8. // 定义可能的环境类型
  9. type Env = 'dev' | 'prod';
  10. // 定义 API URL 配置
  11. const API_URL: Record<Env, string> = {
  12. dev: 'http://localhost:3000',
  13. prod: 'https://lvyin20.tv',
  14. };
  15. /**
  16. * @name 使用公共路径
  17. * @description 部署时的路径,如果部署在非根目录下,需要配置这个变量
  18. * @doc https://umijs.org/docs/api/config#publicpath
  19. */
  20. const PUBLIC_PATH: string = '/';
  21. export default defineConfig({
  22. define: {
  23. // 使用类型断言来确保 REACT_APP_ENV 是有效的键
  24. API_URL: API_URL[REACT_APP_ENV as Env] || API_URL.dev,
  25. },
  26. /**
  27. * @name 开启 hash 模式
  28. * @description 让 build 之后的产物包含 hash 后缀。通常用于增量发布和避免浏览器加载缓存。
  29. * @doc https://umijs.org/docs/api/config#hash
  30. */
  31. hash: true,
  32. publicPath: PUBLIC_PATH,
  33. /**
  34. * @name 兼容性设置
  35. * @description 设置 ie11 不一定完美兼容,需要检查自己使用的所有依赖
  36. * @doc https://umijs.org/docs/api/config#targets
  37. */
  38. // targets: {
  39. // ie: 11,
  40. // },
  41. /**
  42. * @name 路由的配置,不在路由中引入的文件不会编译
  43. * @description 只支持 path,component,routes,redirect,wrappers,title 的配置
  44. * @doc https://umijs.org/docs/guides/routes
  45. */
  46. // umi routes: https://umijs.org/docs/routing
  47. routes,
  48. /**
  49. * @name 主题的配置
  50. * @description 虽然叫主题,但是其实只是 less 的变量设置
  51. * @doc antd的主题设置 https://ant.design/docs/react/customize-theme-cn
  52. * @doc umi 的theme 配置 https://umijs.org/docs/api/config#theme
  53. */
  54. theme: {
  55. // 如果不想要 configProvide 动态设置主题需要把这个设置为 default
  56. // 只有设置为 variable, 才能使用 configProvide 动态设置主色调
  57. 'root-entry-name': 'variable',
  58. },
  59. /**
  60. * @name moment 的国际化配置
  61. * @description 如果对国际化没有要求,打开之后能减少js的包大小
  62. * @doc https://umijs.org/docs/api/config#ignoremomentlocale
  63. */
  64. ignoreMomentLocale: true,
  65. /**
  66. * @name 代理配置
  67. * @description 可以让你的本地服务器代理到你的服务器上,这样你就可以访问服务器的数据了
  68. * @see 要注意以下 代理只能在本地开发时使用,build 之后就无法使用了。
  69. * @doc 代理介绍 https://umijs.org/docs/guides/proxy
  70. * @doc 代理配置 https://umijs.org/docs/api/config#proxy
  71. */
  72. proxy: proxy[REACT_APP_ENV as keyof typeof proxy],
  73. /**
  74. * @name 快速热更新配置
  75. * @description 一个不错的热更新组件,更新时可以保留 state
  76. */
  77. fastRefresh: true,
  78. //============== 以下都是max的插件配置 ===============
  79. /**
  80. * @name 数据流插件
  81. * @@doc https://umijs.org/docs/max/data-flow
  82. */
  83. model: {},
  84. /**
  85. * 一个全局的初始数据流,可以用它在插件之间共享数据
  86. * @description 可以用来存放一些全局的数据,比如用户信息,或者一些全局的状态,全局初始状态在整个 Umi 项目的最开始创建。
  87. * @doc https://umijs.org/docs/max/data-flow#%E5%85%A8%E5%B1%80%E5%88%9D%E5%A7%8B%E7%8A%B6%E6%80%81
  88. */
  89. initialState: {},
  90. /**
  91. * @name layout 插件
  92. * @doc https://umijs.org/docs/max/layout-menu
  93. */
  94. title: '球赛预测管理后台',
  95. layout: {
  96. locale: true,
  97. ...defaultSettings,
  98. },
  99. /**
  100. * @name moment2dayjs 插件
  101. * @description 将项目中的 moment 替换为 dayjs
  102. * @doc https://umijs.org/docs/max/moment2dayjs
  103. */
  104. moment2dayjs: {
  105. preset: 'antd',
  106. plugins: ['duration'],
  107. },
  108. /**
  109. * @name 国际化插件
  110. * @doc https://umijs.org/docs/max/i18n
  111. */
  112. locale: {
  113. // default zh-CN
  114. default: 'zh-CN',
  115. antd: true,
  116. // default true, when it is true, will use `navigator.language` overwrite default
  117. baseNavigator: true,
  118. },
  119. /**
  120. * @name antd 插件
  121. * @description 内置了 babel import 插件
  122. * @doc https://umijs.org/docs/max/antd#antd
  123. */
  124. antd: {},
  125. /**
  126. * @name 网络请求配置
  127. * @description 它基于 axios 和 ahooks 的 useRequest 提供了一套统一的网络请求和错误处理方案。
  128. * @doc https://umijs.org/docs/max/request
  129. */
  130. request: {},
  131. /**
  132. * @name 权限插件
  133. * @description 基于 initialState 的权限插件,必须先打开 initialState
  134. * @doc https://umijs.org/docs/max/access
  135. */
  136. access: {},
  137. /**
  138. * @name <head> 中额外的 script
  139. * @description 配置 <head> 中额外的 script
  140. */
  141. headScripts: [
  142. // 解决首次加载时白屏的问题
  143. { src: join(PUBLIC_PATH, 'scripts/loading.js'), async: true },
  144. ],
  145. //================ pro 插件配置 =================
  146. presets: ['umi-presets-pro'],
  147. mfsu: {
  148. strategy: 'normal',
  149. },
  150. esbuildMinifyIIFE: true,
  151. requestRecord: {},
  152. });