config.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. 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. // 针对 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. defaultGitUrl: 'https://github.com/ant-design/pro-blocks',
  69. },
  70. hash: true,
  71. targets: {
  72. ie: 11,
  73. },
  74. devtool: isAntDesignProPreview ? 'source-map' : false,
  75. // umi routes: https://umijs.org/zh/guide/router.html
  76. routes: [
  77. {
  78. path: '/',
  79. component: '../layouts/BasicLayout',
  80. Routes: ['src/pages/Authorized'],
  81. authority: ['admin', 'user'],
  82. routes: [
  83. {
  84. path: '/',
  85. name: 'welcome',
  86. icon: 'smile',
  87. component: './Welcome',
  88. },
  89. ],
  90. },
  91. ],
  92. // Theme for antd: https://ant.design/docs/react/customize-theme-cn
  93. theme: {
  94. 'primary-color': primaryColor,
  95. },
  96. define: {
  97. ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION:
  98. 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 专用环境变量,请不要在你的项目中使用它。
  99. },
  100. ignoreMomentLocale: true,
  101. lessLoaderOptions: {
  102. javascriptEnabled: true,
  103. },
  104. disableRedirectHoist: true,
  105. cssLoaderOptions: {
  106. modules: true,
  107. getLocalIdent: (
  108. context: {
  109. resourcePath: string;
  110. },
  111. _: string,
  112. localName: string,
  113. ) => {
  114. if (
  115. context.resourcePath.includes('node_modules') ||
  116. context.resourcePath.includes('ant.design.pro.less') ||
  117. context.resourcePath.includes('global.less')
  118. ) {
  119. return localName;
  120. }
  121. const match = context.resourcePath.match(/src(.*)/);
  122. if (match && match[1]) {
  123. const antdProPath = match[1].replace('.less', '');
  124. const arr = slash(antdProPath)
  125. .split('/')
  126. .map((a: string) => a.replace(/([A-Z])/g, '-$1'))
  127. .map((a: string) => a.toLowerCase());
  128. return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
  129. }
  130. return localName;
  131. },
  132. },
  133. manifest: {
  134. basePath: '/',
  135. },
  136. chainWebpack: webpackPlugin,
  137. /*
  138. proxy: {
  139. '/server/api/': {
  140. target: 'https://preview.pro.ant.design/',
  141. changeOrigin: true,
  142. pathRewrite: { '^/server': '' },
  143. },
  144. },
  145. */
  146. } as IConfig;