config.ts 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. // https://umijs.org/config/
  2. import { defineConfig, utils } from 'umi';
  3. import defaultSettings from './defaultSettings';
  4. import proxy from './proxy';
  5. import webpackPlugin from './plugin.config';
  6. const { winPath } = utils; // preview.pro.ant.design only do not use in your production ;
  7. // preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。
  8. const { ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION, REACT_APP_ENV, GA_KEY } = process.env;
  9. export default defineConfig({
  10. history: {
  11. type: 'hash',
  12. },
  13. // 默认是 browser
  14. hash: true,
  15. antd: {},
  16. analytics: GA_KEY
  17. ? {
  18. ga: GA_KEY,
  19. }
  20. : false,
  21. dva: {
  22. hmr: true,
  23. },
  24. locale: {
  25. // default zh-CN
  26. default: 'zh-CN',
  27. // default true, when it is true, will use `navigator.language` overwrite default
  28. antd: true,
  29. baseNavigator: true,
  30. },
  31. dynamicImport: {
  32. loading: '@/components/PageLoading/index',
  33. },
  34. targets: {
  35. ie: 11,
  36. },
  37. // 原来没有这个配置,加上是为了临时解决title为空的问题,github上说是layOut插件的锅,但是一直没有解决
  38. // antd pro更新太快,bug太多
  39. title: false,
  40. // umi routes: https://umijs.org/docs/routing
  41. routes: [
  42. {
  43. path: '/user',
  44. component: '../layouts/UserLayout',
  45. routes: [
  46. {
  47. name: 'login',
  48. path: '/user/login',
  49. component: './user/login',
  50. },
  51. {
  52. name: '注册页',
  53. icon: 'smile',
  54. path: '/user/register',
  55. component: './user/Register',
  56. },
  57. ],
  58. },
  59. {
  60. path: '/',
  61. component: '../layouts/SecurityLayout',
  62. routes: [
  63. {
  64. path: '/',
  65. component: '../layouts/BasicLayout',
  66. // authority: ['admin', 'user'],
  67. routes: [
  68. {
  69. path: '/',
  70. redirect: '/memory',
  71. }, // {
  72. // path: '/welcome',
  73. // name: 'welcome',
  74. // icon: 'smile',
  75. // component: './Welcome',
  76. // },
  77. // {
  78. // path: '/admin',
  79. // name: 'admin',
  80. // icon: 'crown',
  81. // component: './Admin',
  82. // authority: ['admin'],
  83. // routes: [
  84. // {
  85. // path: '/admin/sub-page',
  86. // name: 'sub-page',
  87. // icon: 'smile',
  88. // component: './Welcome',
  89. // authority: ['admin'],
  90. // },
  91. // ],
  92. // },
  93. // {
  94. // name: 'list.table-list',
  95. // icon: 'table',
  96. // path: '/list',
  97. // component: './ListTableList',
  98. // },
  99. {
  100. name: 'list.memory',
  101. icon: 'smile',
  102. path: '/memory',
  103. component: './Memory',
  104. },
  105. {
  106. name: 'list.memoryList',
  107. icon: 'smile',
  108. path: '/memoryList',
  109. component: './MemoryList',
  110. },
  111. {
  112. name: 'list.setting',
  113. icon: 'smile',
  114. path: '/setting',
  115. component: './Setting',
  116. },
  117. {
  118. name: 'list.userList',
  119. icon: 'smile',
  120. path: '/userList',
  121. authority: ['1'],
  122. component: './UserList',
  123. },
  124. {
  125. component: './404',
  126. },
  127. ],
  128. },
  129. {
  130. component: './404',
  131. },
  132. ],
  133. },
  134. {
  135. component: './404',
  136. },
  137. ],
  138. // Theme for antd: https://ant.design/docs/react/customize-theme-cn
  139. theme: {
  140. // ...darkTheme,
  141. 'primary-color': defaultSettings.primaryColor,
  142. },
  143. define: {
  144. REACT_APP_ENV: REACT_APP_ENV || false,
  145. ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION:
  146. ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION || '', // preview.pro.ant.design only do not use in your production ; preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。
  147. },
  148. ignoreMomentLocale: true,
  149. lessLoader: {
  150. javascriptEnabled: true,
  151. },
  152. cssLoader: {
  153. modules: {
  154. getLocalIdent: (
  155. context: {
  156. resourcePath: string;
  157. },
  158. _: string,
  159. localName: string
  160. ) => {
  161. if (
  162. context.resourcePath.includes('node_modules') ||
  163. context.resourcePath.includes('ant.design.pro.less') ||
  164. context.resourcePath.includes('global.less')
  165. ) {
  166. return localName;
  167. }
  168. const match = context.resourcePath.match(/src(.*)/);
  169. if (match && match[1]) {
  170. const antdProPath = match[1].replace('.less', '');
  171. const arr = winPath(antdProPath)
  172. .split('/')
  173. .map((a: string) => a.replace(/([A-Z])/g, '-$1'))
  174. .map((a: string) => a.toLowerCase());
  175. return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
  176. }
  177. return localName;
  178. },
  179. },
  180. },
  181. manifest: {
  182. basePath: '/',
  183. },
  184. proxy: proxy[REACT_APP_ENV || 'dev'],
  185. chainWebpack: webpackPlugin,
  186. });