config.ts 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. // https://umijs.org/config/
  2. import { defineConfig } from '@umijs/max';
  3. import defaultSettings from './defaultSettings';
  4. import proxy from './proxy';
  5. import routes from './routes';
  6. import { toHump } from './util';
  7. const { REACT_APP_ENV = 'dev' } = process.env;
  8. export default defineConfig({
  9. mock: false,
  10. extraPostCSSPlugins: [
  11. require('postcss-import'),
  12. require('tailwindcss'),
  13. require('postcss-nested'), // or require('postcss-nesting')
  14. require('autoprefixer'),
  15. ],
  16. /**
  17. * @name 开启 hash 模式
  18. * @description 让 build 之后的产物包含 hash 后缀。通常用于增量发布和避免浏览器加载缓存。
  19. * @doc https://umijs.org/docs/api/config#hash
  20. */
  21. hash: true,
  22. /**
  23. * @name 兼容性设置
  24. * @description 设置 ie11 不一定完美兼容,需要检查自己使用的所有依赖
  25. * @doc https://umijs.org/docs/api/config#targets
  26. */
  27. // targets: {
  28. // ie: 11,
  29. // },
  30. /**
  31. * @name 路由的配置,不在路由中引入的文件不会编译
  32. * @description 只支持 path,component,routes,redirect,wrappers,title 的配置
  33. * @doc https://umijs.org/docs/guides/routes
  34. */
  35. // umi routes: https://umijs.org/docs/routing
  36. routes,
  37. /**
  38. * @name 主题的配置
  39. * @description 虽然叫主题,但是其实只是 less 的变量设置
  40. * @doc antd的主题设置 https://ant.design/docs/react/customize-theme-cn
  41. * @doc umi 的theme 配置 https://umijs.org/docs/api/config#theme
  42. */
  43. theme: {
  44. // 如果不想要 configProvide 动态设置主题需要把这个设置为 default
  45. // 只有设置为 variable, 才能使用 configProvide 动态设置主色调
  46. 'root-entry-name': 'variable',
  47. },
  48. /**
  49. * @name moment 的国际化配置
  50. * @description 如果对国际化没有要求,打开之后能减少js的包大小
  51. * @doc https://umijs.org/docs/api/config#ignoremomentlocale
  52. */
  53. ignoreMomentLocale: true,
  54. /**
  55. * @name 代理配置
  56. * @description 可以让你的本地服务器代理到你的服务器上,这样你就可以访问服务器的数据了
  57. * @see 要注意以下 代理只能在本地开发时使用,build 之后就无法使用了。
  58. * @doc 代理介绍 https://umijs.org/docs/guides/proxy
  59. * @doc 代理配置 https://umijs.org/docs/api/config#proxy
  60. */
  61. proxy: proxy[REACT_APP_ENV as keyof typeof proxy],
  62. /**
  63. * @name 快速热更新配置
  64. * @description 一个不错的热更新组件,更新时可以保留 state
  65. */
  66. fastRefresh: true,
  67. //============== 以下都是max的插件配置 ===============
  68. /**
  69. * @name 数据流插件
  70. * @@doc https://umijs.org/docs/max/data-flow
  71. */
  72. model: {},
  73. /**
  74. * 一个全局的初始数据流,可以用它在插件之间共享数据
  75. * @description 可以用来存放一些全局的数据,比如用户信息,或者一些全局的状态,全局初始状态在整个 Umi 项目的最开始创建。
  76. * @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
  77. */
  78. initialState: {},
  79. /**
  80. * @name layout 插件
  81. * @doc https://umijs.org/docs/max/layout-menu
  82. */
  83. title: 'Sect管理后台',
  84. layout: {
  85. locale: true,
  86. ...defaultSettings,
  87. },
  88. /**
  89. * @name moment2dayjs 插件
  90. * @description 将项目中的 moment 替换为 dayjs
  91. * @doc https://umijs.org/docs/max/moment2dayjs
  92. */
  93. moment2dayjs: {
  94. preset: 'antd',
  95. plugins: ['duration'],
  96. },
  97. /**
  98. * @name 国际化插件
  99. * @doc https://umijs.org/docs/max/i18n
  100. */
  101. locale: {
  102. // default zh-CN
  103. default: 'zh-CN',
  104. antd: true,
  105. // default true, when it is true, will use `navigator.language` overwrite default
  106. baseNavigator: true,
  107. },
  108. /**
  109. * @name antd 插件
  110. * @description 内置了 babel import 插件
  111. * @doc https://umijs.org/docs/max/antd#antd
  112. */
  113. antd: {
  114. theme: {
  115. token: {
  116. borderRadius: 0,
  117. },
  118. },
  119. },
  120. /**
  121. * @name 网络请求配置
  122. * @description 它基于 axios 和 ahooks 的 useRequest 提供了一套统一的网络请求和错误处理方案。
  123. * @doc https://umijs.org/docs/max/request
  124. */
  125. request: {},
  126. /**
  127. * @name 权限插件
  128. * @description 基于 initialState 的权限插件,必须先打开 initialState
  129. * @doc https://umijs.org/docs/max/access
  130. */
  131. access: {},
  132. /**
  133. * @name <head> 中额外的 script
  134. * @description 配置 <head> 中额外的 script
  135. */
  136. headScripts: [
  137. // 解决首次加载时白屏的问题
  138. { src: '/scripts/loading.js', async: true },
  139. ],
  140. //================ pro 插件配置 =================
  141. presets: ['umi-presets-pro'],
  142. /**
  143. * @name openAPI 插件的配置
  144. * @description 基于 openapi 的规范生成serve 和mock,能减少很多样板代码
  145. * @doc https://pro.ant.design/zh-cn/docs/openapi/
  146. */
  147. openAPI: [
  148. // {
  149. // requestLibPath: "import { request } from '@umijs/max'",
  150. // // 或者使用在线的版本
  151. // // schemaPath: "https://gw.alipayobjects.com/os/antfincdn/M%24jrzTTYJN/oneapi.json"
  152. // schemaPath: join(__dirname, 'oneapi.json'),
  153. // mock: false,
  154. // },
  155. // {
  156. // requestLibPath: "import { request } from '@umijs/max'",
  157. // schemaPath: 'https://gw.alipayobjects.com/os/antfincdn/M%24jrzTTYJN/oneapi.json',
  158. {
  159. requestLibPath: "import { invoke as request } from '@/core/network'",
  160. schemaPath: 'https://sect.nosum.cn/v3/api-docs',
  161. namespace: 'SectApi',
  162. projectName: 'swagger',
  163. hook: {
  164. customFunctionName: (...arg: any[]) => {
  165. const [data] = arg
  166. const names = data.path.replace(/\/apis\/clients/g, '').replace(/\/apis\/admin/g, '').split('/')
  167. const rawName = names.reduce((acc: string, name: string) => {
  168. if(!name || ['apis', 'admin', 'clients'].includes(name)) return acc
  169. return acc + '_' +name
  170. }, data.method) + 'Api'
  171. const name = toHump(rawName)
  172. return name
  173. },
  174. // customClassName: (...arg) => {
  175. // console.log('sect customClassName:', ...arg)
  176. // }
  177. }
  178. },
  179. ],
  180. mfsu: {
  181. strategy: 'eager',
  182. },
  183. esbuildMinifyIIFE: true,
  184. requestRecord: {},
  185. });