config.ts 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. // umi routes: https://umijs.org/docs/routing
  38. routes: [
  39. {
  40. path: '/user',
  41. component: '../layouts/UserLayout',
  42. routes: [
  43. {
  44. name: 'login',
  45. path: '/user/login',
  46. component: './user/login',
  47. },
  48. {
  49. name: '注册页',
  50. icon: 'smile',
  51. path: '/user/register',
  52. component: './user/Register',
  53. },
  54. ],
  55. },
  56. {
  57. path: '/',
  58. component: '../layouts/SecurityLayout',
  59. routes: [
  60. {
  61. path: '/',
  62. component: '../layouts/BasicLayout',
  63. // authority: ['admin', 'user'],
  64. routes: [
  65. {
  66. path: '/',
  67. redirect: '/memory',
  68. }, // {
  69. // path: '/welcome',
  70. // name: 'welcome',
  71. // icon: 'smile',
  72. // component: './Welcome',
  73. // },
  74. // {
  75. // path: '/admin',
  76. // name: 'admin',
  77. // icon: 'crown',
  78. // component: './Admin',
  79. // authority: ['admin'],
  80. // routes: [
  81. // {
  82. // path: '/admin/sub-page',
  83. // name: 'sub-page',
  84. // icon: 'smile',
  85. // component: './Welcome',
  86. // authority: ['admin'],
  87. // },
  88. // ],
  89. // },
  90. // {
  91. // name: 'list.table-list',
  92. // icon: 'table',
  93. // path: '/list',
  94. // component: './ListTableList',
  95. // },
  96. {
  97. name: 'list.memory',
  98. icon: 'smile',
  99. path: '/memory',
  100. component: './Memory',
  101. },
  102. {
  103. name: 'list.memoryList',
  104. icon: 'smile',
  105. path: '/memoryList',
  106. component: './MemoryList',
  107. },
  108. {
  109. name: 'list.setting',
  110. icon: 'smile',
  111. path: '/setting',
  112. component: './Setting',
  113. },
  114. {
  115. name: 'list.userList',
  116. icon: 'smile',
  117. path: '/userList',
  118. authority: ['1'],
  119. component: './UserList',
  120. },
  121. {
  122. component: './404',
  123. },
  124. ],
  125. },
  126. {
  127. component: './404',
  128. },
  129. ],
  130. },
  131. {
  132. component: './404',
  133. },
  134. ],
  135. // Theme for antd: https://ant.design/docs/react/customize-theme-cn
  136. theme: {
  137. // ...darkTheme,
  138. 'primary-color': defaultSettings.primaryColor,
  139. },
  140. define: {
  141. REACT_APP_ENV: REACT_APP_ENV || false,
  142. ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION:
  143. 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 专用环境变量,请不要在你的项目中使用它。
  144. },
  145. ignoreMomentLocale: true,
  146. lessLoader: {
  147. javascriptEnabled: true,
  148. },
  149. cssLoader: {
  150. modules: {
  151. getLocalIdent: (
  152. context: {
  153. resourcePath: string;
  154. },
  155. _: string,
  156. localName: string
  157. ) => {
  158. if (
  159. context.resourcePath.includes('node_modules') ||
  160. context.resourcePath.includes('ant.design.pro.less') ||
  161. context.resourcePath.includes('global.less')
  162. ) {
  163. return localName;
  164. }
  165. const match = context.resourcePath.match(/src(.*)/);
  166. if (match && match[1]) {
  167. const antdProPath = match[1].replace('.less', '');
  168. const arr = winPath(antdProPath)
  169. .split('/')
  170. .map((a: string) => a.replace(/([A-Z])/g, '-$1'))
  171. .map((a: string) => a.toLowerCase());
  172. return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
  173. }
  174. return localName;
  175. },
  176. },
  177. },
  178. manifest: {
  179. basePath: '/',
  180. },
  181. proxy: proxy[REACT_APP_ENV || 'dev'],
  182. chainWebpack: webpackPlugin, // scripts: [
  183. // 'https://unpkg.com/react@16.8.6/umd/react.production.min.js',
  184. // 'https://unpkg.com/react-dom@16.8.6/umd/react-dom.production.min.js',
  185. // 'https://unpkg.com/bizcharts@3.5.5/umd/BizCharts.min.js',
  186. // 'https://cdn.bootcss.com/antd/4.0.0/antd.min.js',
  187. // ],
  188. // externals: {
  189. // react: 'React',
  190. // antd: 'antd',
  191. // 'react-dom': 'ReactDOM',
  192. // bizcharts: 'BizCharts',
  193. // },
  194. });