config.js 4.9KB

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