config.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. // https://umijs.org/config/
  2. import { join } from 'node:path';
  3. import { defineConfig } from '@umijs/max';
  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. * @name 使用公共路径
  10. * @description 部署时的路径,如果部署在非根目录下,需要配置这个变量
  11. * @doc https://umijs.org/docs/api/config#publicpath
  12. */
  13. const PUBLIC_PATH: string = '/';
  14. export default defineConfig({
  15. history: {
  16. type: 'hash',
  17. },
  18. /**
  19. * @name 开启 hash 模式
  20. * @description 让 build 之后的产物包含 hash 后缀。通常用于增量发布和避免浏览器加载缓存。
  21. * @doc https://umijs.org/docs/api/config#hash
  22. */
  23. hash: true,
  24. publicPath: PUBLIC_PATH,
  25. /**
  26. * @name 兼容性设置
  27. * @description 设置 ie11 不一定完美兼容,需要检查自己使用的所有依赖
  28. * @doc https://umijs.org/docs/api/config#targets
  29. */
  30. // targets: {
  31. // ie: 11,
  32. // },
  33. /**
  34. * @name 路由的配置,不在路由中引入的文件不会编译
  35. * @description 只支持 path,component,routes,redirect,wrappers,title 的配置
  36. * @doc https://umijs.org/docs/guides/routes
  37. */
  38. // umi routes: https://umijs.org/docs/routing
  39. routes,
  40. /**
  41. * @name 主题的配置
  42. * @description 虽然叫主题,但是其实只是 less 的变量设置
  43. * @doc antd的主题设置 https://ant.design/docs/react/customize-theme-cn
  44. * @doc umi 的 theme 配置 https://umijs.org/docs/api/config#theme
  45. */
  46. // theme: { '@primary-color': '#1DA57A' }
  47. /**
  48. * @name moment 的国际化配置
  49. * @description 如果对国际化没有要求,打开之后能减少js的包大小
  50. * @doc https://umijs.org/docs/api/config#ignoremomentlocale
  51. */
  52. ignoreMomentLocale: true,
  53. /**
  54. * @name 代理配置
  55. * @description 可以让你的本地服务器代理到你的服务器上,这样你就可以访问服务器的数据了
  56. * @see 要注意以下 代理只能在本地开发时使用,build 之后就无法使用了。
  57. * @doc 代理介绍 https://umijs.org/docs/guides/proxy
  58. * @doc 代理配置 https://umijs.org/docs/api/config#proxy
  59. */
  60. proxy: proxy[REACT_APP_ENV as keyof typeof proxy],
  61. /**
  62. * @name 快速热更新配置
  63. * @description 一个不错的热更新组件,更新时可以保留 state
  64. */
  65. fastRefresh: true,
  66. //============== 以下都是max的插件配置 ===============
  67. /**
  68. * @name 数据流插件
  69. * @@doc https://umijs.org/docs/max/data-flow
  70. */
  71. model: {},
  72. /**
  73. * 一个全局的初始数据流,可以用它在插件之间共享数据
  74. * @description 可以用来存放一些全局的数据,比如用户信息,或者一些全局的状态,全局初始状态在整个 Umi 项目的最开始创建。
  75. * @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
  76. */
  77. initialState: {},
  78. /**
  79. * @name layout 插件
  80. * @doc https://umijs.org/docs/max/layout-menu
  81. */
  82. title: '趣程游戏数据系统',
  83. layout: {
  84. locale: true,
  85. ...defaultSettings,
  86. },
  87. /**
  88. * @name moment2dayjs 插件
  89. * @description 将项目中的 moment 替换为 dayjs
  90. * @doc https://umijs.org/docs/max/moment2dayjs
  91. */
  92. moment2dayjs: {
  93. preset: 'antd',
  94. plugins: ['duration'],
  95. },
  96. /**
  97. * @name 国际化插件
  98. * @doc https://umijs.org/docs/max/i18n
  99. */
  100. locale: false,
  101. /**
  102. * @name antd 插件
  103. * @description 内置了 babel import 插件
  104. * @doc https://umijs.org/docs/max/antd#antd
  105. */
  106. antd: {
  107. appConfig: {},
  108. configProvider: {
  109. theme: {
  110. cssVar: true,
  111. token: {
  112. fontFamily: 'AlibabaSans, sans-serif',
  113. },
  114. },
  115. },
  116. },
  117. /**
  118. * @name 网络请求配置
  119. * @description 它基于 axios 和 ahooks 的 useRequest 提供了一套统一的网络请求和错误处理方案。
  120. * @doc https://umijs.org/docs/max/request
  121. */
  122. request: {},
  123. /**
  124. * @name 权限插件
  125. * @description 基于 initialState 的权限插件,必须先打开 initialState
  126. * @doc https://umijs.org/docs/max/access
  127. */
  128. access: {},
  129. /**
  130. * @name <head> 中额外的 script
  131. * @description 配置 <head> 中额外的 script
  132. */
  133. headScripts: [
  134. // 解决首次加载时白屏的问题
  135. { src: join(PUBLIC_PATH, 'scripts/loading.js'), async: true },
  136. ],
  137. //================ pro 插件配置 =================
  138. presets: ['umi-presets-pro'],
  139. /**
  140. * @name openAPI 插件的配置
  141. * @description 基于 openapi 的规范生成serve 和mock,能减少很多样板代码
  142. * @doc https://pro.ant.design/zh-cn/docs/openapi/
  143. */
  144. openAPI: [
  145. {
  146. requestLibPath: "import { request } from '@umijs/max'",
  147. // 或者使用在线的版本
  148. // schemaPath: "https://gw.alipayobjects.com/os/antfincdn/M%24jrzTTYJN/oneapi.json"
  149. schemaPath: join(__dirname, 'oneapi.json'),
  150. mock: false,
  151. },
  152. {
  153. requestLibPath: "import { request } from '@umijs/max'",
  154. schemaPath:
  155. 'https://gw.alipayobjects.com/os/antfincdn/CA1dOm%2631B/openapi.json',
  156. projectName: 'swagger',
  157. },
  158. ],
  159. mock: {
  160. include: ['mock/**/*', 'src/pages/**/_mock.ts'],
  161. },
  162. /**
  163. * @name 是否开启 mako
  164. * @description 使用 mako 极速研发
  165. * @doc https://umijs.org/docs/api/config#mako
  166. */
  167. mako: {},
  168. esbuildMinifyIIFE: true,
  169. requestRecord: {},
  170. exportStatic: {},
  171. });