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