config.ts 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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([
  69. 'umi-plugin-pro',
  70. {
  71. serverUrl: 'https://us-central1-antd-pro.cloudfunctions.net/api',
  72. },
  73. ]);
  74. plugins.push(['umi-plugin-antd-theme', themePluginConfig]);
  75. }
  76. export default {
  77. plugins,
  78. hash: true,
  79. targets: {
  80. ie: 11,
  81. },
  82. // umi routes: https://umijs.org/zh/guide/router.html
  83. routes: [
  84. {
  85. path: '/user',
  86. component: '../layouts/UserLayout',
  87. routes: [
  88. {
  89. name: 'login',
  90. path: '/user/login',
  91. component: './user/login',
  92. },
  93. ],
  94. },
  95. {
  96. path: '/',
  97. component: '../layouts/SecurityLayout',
  98. routes: [
  99. {
  100. path: '/',
  101. component: '../layouts/BasicLayout',
  102. authority: ['admin', 'user'],
  103. routes: [
  104. {
  105. path: '/',
  106. redirect: '/welcome',
  107. },
  108. {
  109. path: '/welcome',
  110. name: 'welcome',
  111. icon: 'smile',
  112. component: './Welcome',
  113. },
  114. {
  115. path: '/admin',
  116. name: 'admin',
  117. icon: 'crown',
  118. component: './Admin',
  119. authority: ['admin'],
  120. routes: [
  121. {
  122. path: '/admin/sub-page',
  123. name: 'sub-page',
  124. icon: 'smile',
  125. component: './Welcome',
  126. authority: ['admin'],
  127. },
  128. ],
  129. },
  130. {
  131. name: 'list.table-list',
  132. icon: 'table',
  133. path: '/list',
  134. component: './ListTableList',
  135. },
  136. {
  137. component: './404',
  138. },
  139. ],
  140. },
  141. {
  142. component: './404',
  143. },
  144. ],
  145. },
  146. {
  147. component: './404',
  148. },
  149. ],
  150. // Theme for antd: https://ant.design/docs/react/customize-theme-cn
  151. theme: {
  152. // ...darkTheme,
  153. 'primary-color': defaultSettings.primaryColor,
  154. },
  155. define: {
  156. REACT_APP_ENV: REACT_APP_ENV || false,
  157. ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION:
  158. 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 专用环境变量,请不要在你的项目中使用它。
  159. },
  160. ignoreMomentLocale: true,
  161. lessLoaderOptions: {
  162. javascriptEnabled: true,
  163. },
  164. disableRedirectHoist: true,
  165. cssLoaderOptions: {
  166. modules: true,
  167. getLocalIdent: (
  168. context: {
  169. resourcePath: string;
  170. },
  171. _: string,
  172. localName: string,
  173. ) => {
  174. if (
  175. context.resourcePath.includes('node_modules') ||
  176. context.resourcePath.includes('ant.design.pro.less') ||
  177. context.resourcePath.includes('global.less')
  178. ) {
  179. return localName;
  180. }
  181. const match = context.resourcePath.match(/src(.*)/);
  182. if (match && match[1]) {
  183. const antdProPath = match[1].replace('.less', '');
  184. const arr = slash(antdProPath)
  185. .split('/')
  186. .map((a: string) => a.replace(/([A-Z])/g, '-$1'))
  187. .map((a: string) => a.toLowerCase());
  188. return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
  189. }
  190. return localName;
  191. },
  192. },
  193. manifest: {
  194. basePath: '/',
  195. },
  196. proxy: proxy[REACT_APP_ENV || 'dev'],
  197. chainWebpack: webpackPlugin,
  198. } as IConfig;