config.ts 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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.memoryList',
  96. icon: 'smile',
  97. path: '/memoryList',
  98. component: './MemoryList',
  99. },
  100. {
  101. name: 'list.setting',
  102. icon: 'smile',
  103. path: '/setting',
  104. component: './Setting',
  105. },
  106. {
  107. name: 'list.userList',
  108. icon: 'smile',
  109. path: '/userList',
  110. authority: ['1'],
  111. component: './UserList',
  112. },
  113. {
  114. component: './404',
  115. },
  116. ],
  117. },
  118. {
  119. component: './404',
  120. },
  121. ],
  122. },
  123. {
  124. component: './404',
  125. },
  126. ],
  127. // Theme for antd: https://ant.design/docs/react/customize-theme-cn
  128. theme: {
  129. // ...darkTheme,
  130. 'primary-color': defaultSettings.primaryColor,
  131. },
  132. define: {
  133. REACT_APP_ENV: REACT_APP_ENV || false,
  134. ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION:
  135. 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 专用环境变量,请不要在你的项目中使用它。
  136. },
  137. ignoreMomentLocale: true,
  138. lessLoader: {
  139. javascriptEnabled: true,
  140. },
  141. cssLoader: {
  142. modules: {
  143. getLocalIdent: (
  144. context: {
  145. resourcePath: string;
  146. },
  147. _: string,
  148. localName: string,
  149. ) => {
  150. if (
  151. context.resourcePath.includes('node_modules') ||
  152. context.resourcePath.includes('ant.design.pro.less') ||
  153. context.resourcePath.includes('global.less')
  154. ) {
  155. return localName;
  156. }
  157. const match = context.resourcePath.match(/src(.*)/);
  158. if (match && match[1]) {
  159. const antdProPath = match[1].replace('.less', '');
  160. const arr = winPath(antdProPath)
  161. .split('/')
  162. .map((a: string) => a.replace(/([A-Z])/g, '-$1'))
  163. .map((a: string) => a.toLowerCase());
  164. return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
  165. }
  166. return localName;
  167. },
  168. },
  169. },
  170. manifest: {
  171. basePath: '/',
  172. },
  173. proxy: proxy[REACT_APP_ENV || 'dev'],
  174. chainWebpack: webpackPlugin,
  175. // scripts: [
  176. // 'https://unpkg.com/react@16.8.6/umd/react.production.min.js',
  177. // 'https://unpkg.com/react-dom@16.8.6/umd/react-dom.production.min.js',
  178. // 'https://unpkg.com/bizcharts@3.5.5/umd/BizCharts.min.js',
  179. // 'https://cdn.bootcss.com/antd/4.0.0/antd.min.js',
  180. // ],
  181. // externals: {
  182. // react: 'React',
  183. // antd: 'antd',
  184. // 'react-dom': 'ReactDOM',
  185. // bizcharts: 'BizCharts',
  186. // },
  187. });