config.ts 5.0 KB

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