config.ts 5.0 KB

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