config.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. const { pwa } = 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, // default close dll, because issue https://github.com/ant-design/ant-design-pro/issues/4665
  39. // dll features https://webpack.js.org/plugins/dll-plugin/
  40. // dll: {
  41. // include: ['dva', 'dva/router', 'dva/saga', 'dva/fetch'],
  42. // exclude: ['@babel/runtime', 'netlify-lambda'],
  43. // },
  44. },
  45. ],
  46. [
  47. 'umi-plugin-pro-block',
  48. {
  49. moveMock: false,
  50. moveService: false,
  51. modifyRequest: true,
  52. autoAddMenu: true,
  53. },
  54. ],
  55. ];
  56. if (isAntDesignProPreview) {
  57. // 针对 preview.pro.ant.design 的 GA 统计代码
  58. plugins.push([
  59. 'umi-plugin-ga',
  60. {
  61. code: 'UA-72788897-6',
  62. },
  63. ]);
  64. plugins.push(['umi-plugin-antd-theme', themePluginConfig]);
  65. }
  66. export default {
  67. plugins,
  68. hash: true,
  69. targets: {
  70. ie: 11,
  71. },
  72. // umi routes: https://umijs.org/zh/guide/router.html
  73. routes: [
  74. {
  75. path: '/user',
  76. component: '../layouts/UserLayout',
  77. routes: [
  78. {
  79. name: 'login',
  80. path: '/user/login',
  81. component: './user/login',
  82. },
  83. ],
  84. },
  85. {
  86. path: '/',
  87. component: '../layouts/SecurityLayout',
  88. routes: [
  89. {
  90. path: '/',
  91. component: '../layouts/BasicLayout',
  92. authority: ['admin', 'user'],
  93. routes: [
  94. {
  95. path: '/',
  96. redirect: '/welcome',
  97. },
  98. {
  99. path: '/welcome',
  100. name: 'welcome',
  101. icon: 'smile',
  102. component: './Welcome',
  103. },
  104. {
  105. path: '/admin',
  106. name: 'admin',
  107. icon: 'crown',
  108. component: './Admin',
  109. authority: ['admin'],
  110. },
  111. {
  112. component: './404',
  113. },
  114. ],
  115. },
  116. {
  117. component: './404',
  118. },
  119. ],
  120. },
  121. {
  122. component: './404',
  123. },
  124. ],
  125. // Theme for antd: https://ant.design/docs/react/customize-theme-cn
  126. theme: {
  127. // ...darkTheme,
  128. },
  129. define: {
  130. ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION:
  131. 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 专用环境变量,请不要在你的项目中使用它。
  132. },
  133. ignoreMomentLocale: true,
  134. lessLoaderOptions: {
  135. javascriptEnabled: true,
  136. },
  137. disableRedirectHoist: true,
  138. cssLoaderOptions: {
  139. modules: true,
  140. getLocalIdent: (
  141. context: {
  142. resourcePath: string;
  143. },
  144. _: string,
  145. localName: string,
  146. ) => {
  147. if (
  148. context.resourcePath.includes('node_modules') ||
  149. context.resourcePath.includes('ant.design.pro.less') ||
  150. context.resourcePath.includes('global.less')
  151. ) {
  152. return localName;
  153. }
  154. const match = context.resourcePath.match(/src(.*)/);
  155. if (match && match[1]) {
  156. const antdProPath = match[1].replace('.less', '');
  157. const arr = slash(antdProPath)
  158. .split('/')
  159. .map((a: string) => a.replace(/([A-Z])/g, '-$1'))
  160. .map((a: string) => a.toLowerCase());
  161. return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
  162. }
  163. return localName;
  164. },
  165. },
  166. manifest: {
  167. basePath: '/',
  168. },
  169. // chainWebpack: webpackPlugin,
  170. // proxy: {
  171. // '/server/api/': {
  172. // target: 'https://preview.pro.ant.design/',
  173. // changeOrigin: true,
  174. // pathRewrite: { '^/server': '' },
  175. // },
  176. // },
  177. } as IConfig;