config.ts 4.8 KB

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