config.ts 4.1 KB

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