config.ts 3.9 KB

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