config.ts 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. import { IConfig, IPlugin } from 'umi-types';
  2. import defaultSettings from './defaultSettings'; // https://umijs.org/config/
  3. import slash from 'slash2';
  4. import themePluginConfig from './themePluginConfig';
  5. import proxy from './proxy';
  6. const { pwa } = defaultSettings;
  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 } = process.env;
  10. const isAntDesignProPreview = ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site';
  11. const plugins: IPlugin[] = [
  12. ['umi-plugin-antd-icon-config', {}],
  13. [
  14. 'umi-plugin-react',
  15. {
  16. antd: true,
  17. dva: {
  18. hmr: true,
  19. },
  20. locale: {
  21. // default false
  22. enable: true,
  23. // default zh-CN
  24. default: 'zh-CN',
  25. // default true, when it is true, will use `navigator.language` overwrite default
  26. baseNavigator: true,
  27. },
  28. dynamicImport: {
  29. loadingComponent: './components/PageLoading/index',
  30. webpackChunkName: true,
  31. level: 3,
  32. },
  33. pwa: pwa
  34. ? {
  35. workboxPluginMode: 'InjectManifest',
  36. workboxOptions: {
  37. importWorkboxFrom: 'local',
  38. },
  39. }
  40. : false,
  41. // default close dll, because issue https://github.com/ant-design/ant-design-pro/issues/4665
  42. // dll features https://webpack.js.org/plugins/dll-plugin/
  43. // dll: {
  44. // include: ['dva', 'dva/router', 'dva/saga', 'dva/fetch'],
  45. // exclude: ['@babel/runtime', 'netlify-lambda'],
  46. // },
  47. },
  48. ],
  49. [
  50. 'umi-plugin-pro-block',
  51. {
  52. moveMock: false,
  53. moveService: false,
  54. modifyRequest: true,
  55. autoAddMenu: true,
  56. },
  57. ],
  58. ];
  59. if (isAntDesignProPreview) {
  60. // 针对 preview.pro.ant.design 的 GA 统计代码
  61. plugins.push([
  62. 'umi-plugin-ga',
  63. {
  64. code: 'UA-72788897-6',
  65. },
  66. ]);
  67. plugins.push(['umi-plugin-antd-theme', themePluginConfig]);
  68. }
  69. export default {
  70. plugins,
  71. hash: true,
  72. targets: {
  73. ie: 11,
  74. },
  75. // umi routes: https://umijs.org/zh/guide/router.html
  76. routes: [
  77. {
  78. path: '/user',
  79. component: '../layouts/UserLayout',
  80. routes: [
  81. {
  82. name: 'login',
  83. path: '/user/login',
  84. component: './user/login',
  85. },
  86. ],
  87. },
  88. {
  89. path: '/',
  90. component: '../layouts/SecurityLayout',
  91. routes: [
  92. {
  93. path: '/',
  94. component: '../layouts/BasicLayout',
  95. authority: ['admin', 'user'],
  96. routes: [
  97. {
  98. path: '/',
  99. redirect: '/welcome',
  100. },
  101. {
  102. path: '/welcome',
  103. name: 'welcome',
  104. icon: 'smile',
  105. component: './Welcome',
  106. },
  107. {
  108. path: '/admin',
  109. name: 'admin',
  110. icon: 'crown',
  111. component: './Admin',
  112. authority: ['admin'],
  113. routes: [
  114. {
  115. path: '/admin/sub-page',
  116. name: 'sub-page',
  117. icon: 'smile',
  118. component: './Welcome',
  119. authority: ['admin'],
  120. },
  121. ],
  122. },
  123. {
  124. component: './404',
  125. },
  126. ],
  127. },
  128. {
  129. component: './404',
  130. },
  131. ],
  132. },
  133. {
  134. component: './404',
  135. },
  136. ],
  137. // Theme for antd: https://ant.design/docs/react/customize-theme-cn
  138. theme: {
  139. // ...darkTheme,
  140. },
  141. define: {
  142. REACT_APP_ENV: REACT_APP_ENV || false,
  143. ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION:
  144. 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 专用环境变量,请不要在你的项目中使用它。
  145. },
  146. ignoreMomentLocale: true,
  147. lessLoaderOptions: {
  148. javascriptEnabled: true,
  149. },
  150. disableRedirectHoist: true,
  151. cssLoaderOptions: {
  152. modules: true,
  153. getLocalIdent: (
  154. context: {
  155. resourcePath: string;
  156. },
  157. _: string,
  158. localName: string,
  159. ) => {
  160. if (
  161. context.resourcePath.includes('node_modules') ||
  162. context.resourcePath.includes('ant.design.pro.less') ||
  163. context.resourcePath.includes('global.less')
  164. ) {
  165. return localName;
  166. }
  167. const match = context.resourcePath.match(/src(.*)/);
  168. if (match && match[1]) {
  169. const antdProPath = match[1].replace('.less', '');
  170. const arr = slash(antdProPath)
  171. .split('/')
  172. .map((a: string) => a.replace(/([A-Z])/g, '-$1'))
  173. .map((a: string) => a.toLowerCase());
  174. return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
  175. }
  176. return localName;
  177. },
  178. },
  179. manifest: {
  180. basePath: '/',
  181. },
  182. proxy: proxy[REACT_APP_ENV || 'dev'],
  183. } as IConfig;