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