config.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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: { type: 'hash' }, // 默认是 browser
  11. hash: true,
  12. antd: {},
  13. analytics: GA_KEY
  14. ? {
  15. ga: GA_KEY,
  16. }
  17. : false,
  18. dva: {
  19. hmr: true,
  20. },
  21. locale: {
  22. // default zh-CN
  23. default: 'zh-CN',
  24. // default true, when it is true, will use `navigator.language` overwrite default
  25. antd: true,
  26. baseNavigator: true,
  27. },
  28. dynamicImport: {
  29. loading: '@/components/PageLoading/index',
  30. },
  31. targets: {
  32. ie: 11,
  33. },
  34. // umi routes: https://umijs.org/docs/routing
  35. routes: [
  36. {
  37. path: '/user',
  38. component: '../layouts/UserLayout',
  39. routes: [
  40. {
  41. name: 'login',
  42. path: '/user/login',
  43. component: './user/login',
  44. },
  45. ],
  46. },
  47. {
  48. path: '/',
  49. component: '../layouts/SecurityLayout',
  50. routes: [
  51. {
  52. path: '/',
  53. component: '../layouts/BasicLayout',
  54. authority: ['admin', 'user'],
  55. routes: [
  56. {
  57. path: '/',
  58. redirect: '/memory',
  59. },
  60. // {
  61. // path: '/welcome',
  62. // name: 'welcome',
  63. // icon: 'smile',
  64. // component: './Welcome',
  65. // },
  66. // {
  67. // path: '/admin',
  68. // name: 'admin',
  69. // icon: 'crown',
  70. // component: './Admin',
  71. // authority: ['admin'],
  72. // routes: [
  73. // {
  74. // path: '/admin/sub-page',
  75. // name: 'sub-page',
  76. // icon: 'smile',
  77. // component: './Welcome',
  78. // authority: ['admin'],
  79. // },
  80. // ],
  81. // },
  82. // {
  83. // name: 'list.table-list',
  84. // icon: 'table',
  85. // path: '/list',
  86. // component: './ListTableList',
  87. // },
  88. {
  89. name: 'list.memory',
  90. icon: 'smile',
  91. path: '/memory',
  92. component: './Memory',
  93. },
  94. {
  95. name: 'list.setting',
  96. icon: 'smile',
  97. path: '/setting',
  98. component: './Setting',
  99. },
  100. {
  101. component: './404',
  102. },
  103. ],
  104. },
  105. {
  106. component: './404',
  107. },
  108. ],
  109. },
  110. {
  111. component: './404',
  112. },
  113. ],
  114. // Theme for antd: https://ant.design/docs/react/customize-theme-cn
  115. theme: {
  116. // ...darkTheme,
  117. 'primary-color': defaultSettings.primaryColor,
  118. },
  119. define: {
  120. REACT_APP_ENV: REACT_APP_ENV || false,
  121. ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION:
  122. 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 专用环境变量,请不要在你的项目中使用它。
  123. },
  124. ignoreMomentLocale: true,
  125. lessLoader: {
  126. javascriptEnabled: true,
  127. },
  128. cssLoader: {
  129. modules: {
  130. getLocalIdent: (
  131. context: {
  132. resourcePath: string;
  133. },
  134. _: string,
  135. localName: string,
  136. ) => {
  137. if (
  138. context.resourcePath.includes('node_modules') ||
  139. context.resourcePath.includes('ant.design.pro.less') ||
  140. context.resourcePath.includes('global.less')
  141. ) {
  142. return localName;
  143. }
  144. const match = context.resourcePath.match(/src(.*)/);
  145. if (match && match[1]) {
  146. const antdProPath = match[1].replace('.less', '');
  147. const arr = winPath(antdProPath)
  148. .split('/')
  149. .map((a: string) => a.replace(/([A-Z])/g, '-$1'))
  150. .map((a: string) => a.toLowerCase());
  151. return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
  152. }
  153. return localName;
  154. },
  155. },
  156. },
  157. manifest: {
  158. basePath: '/',
  159. },
  160. proxy: proxy[REACT_APP_ENV || 'dev'],
  161. chainWebpack: webpackPlugin,
  162. });