config.ts 5.0 KB

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