config.ts 4.2 KB

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