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